How to save image?

Hi all,
I have drawn an Image using Graphics, and then I have drawn some rectangles on it.
How can I save that image with drawn rectangles?
any idea or link which should I refer?

Example 1:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class WriteImageType {
  static public void main(String args[]) throws Exception {
    try {
      int width = 200, height = 200;
      // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed
      // into integer pixels
      BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D ig2 = bi.createGraphics();
      Font font = new Font("TimesRoman", Font.BOLD, 20);
      ig2.setFont(font);
      String message = "www.java2s.com!";
      FontMetrics fontMetrics = ig2.getFontMetrics();
      int stringWidth = fontMetrics.stringWidth(message);
      int stringHeight = fontMetrics.getAscent();
      ig2.setPaint(Color.black);
      ig2.drawString(message, (width - stringWidth) / 2, height / 2 + stringHeight / 4);
      ImageIO.write(bi, "PNG", new File("c:\\yourImageName.PNG"));
      ImageIO.write(bi, "JPEG", new File("c:\\yourImageName.JPG"));
      ImageIO.write(bi, "gif", new File("c:\\yourImageName.GIF"));
      ImageIO.write(bi, "BMP", new File("c:\\yourImageName.BMP"));
    } catch (IOException ie) {
      ie.printStackTrace();
Example 2:
// Create an image to save
    RenderedImage rendImage = myCreateImage();
    // Write generated image to a file
    try {
        // Save as PNG
        File file = new File("newimage.png");
        ImageIO.write(rendImage, "png", file);
        // Save as JPEG
        file = new File("newimage.jpg");
        ImageIO.write(rendImage, "jpg", file);
    } catch (IOException e) {
    // Returns a generated image.
    public RenderedImage myCreateImage() {
        int width = 100;
        int height = 100;
        // Create a buffered image in which to draw
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        // Create a graphics contents on the buffered image
        Graphics2D g2d = bufferedImage.createGraphics();
        // Draw graphics
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.black);
        g2d.fillOval(0, 0, width, height);
        // Graphics context no longer needed so dispose it
        g2d.dispose();
        return bufferedImage;
    }

Similar Messages

  • How to save image files into SQL Server?

    Hello, All:
    Does anyone know how to save image files into SQL Server? Does the file type have to be changed first?? Please help me! Thank you!

    You need a BLOB field (usually)... Then you can check this tutorial out:
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/
    There are other exercises on that site, including one on reading the images back.

  • How to save image catch from USB camera to database ?

    Hi guys.
    I needed help on IMAQdx tools. But i dont know how to save image that catch from USB camera to database.

    So you can acquire the image OK?
    And you want to save it to a SQL database?
    See here:
    http://zone.ni.com/devzone/cda/epd/p/id/5210

  • E61i -- HOW TO SAVE IMAGES FROM WEBSITE WHILE BROW...

    ANYBODY KNOWS HOW TO SAVE IMAGES FROM WEBSITE WHILE BROWSING IN E61i ???
    ABDULLAH SHAHID SHEIKH
    IMANGROUP, IMAN ROAD, NOORPUR, ALI BLOCK, MUSLIM TOWN, FAISALABAD, PAKISTAN.
    TEL. 0092418782792-93
    CELL. 00923008651424

    which version should i use ,, i mean suitable for my E61i,,, the opera mini or the opera mobile????
    is opera mini can save the images as well???
    25-Aug-200702:43 PM
    iantaylor27 wrote:
    Hi
    If you use opera mobile, it aloows saving of images to memory card etc
    www.opera.com
    ABDULLAH SHAHID SHEIKH
    IMANGROUP, IMAN ROAD, NOORPUR, ALI BLOCK, MUSLIM TOWN, FAISALABAD, PAKISTAN.
    TEL. 0092418782792-93
    CELL. 00923008651424

  • How to Save image in a text to my photos

    How do I save the photo in a text message to my iPad air photos?

    Tap the image in Message. (If you touch too long it brings up the: Copy; Other... menu instead)
    This blows the image up to full screen.
    Touch the image again to get menu options.
    In the top right corner, tap the box with the up arrow.  One choice is Save Image.  Touch it to save to your camera roll.
    In the top left corner, the three-line menu shows you all the photos in the message string, and some metadata like image size and camera title/image number.
    This is in IOS 7.1.1 on an iPad, and should work on iPhone and Touch also.

  • How to save image in database

    hi ,
    I am developing a application. i want to upload image with person's details and save it to database. How to do this? I hv got tutorials for uploading image but want to know how to save it to database table along with person's details.
    Thanks in advance.
    Regards
    Rajaram

    1.Go to transaction SE78.
    2.Select tree menu: Form Graphics -> Stroed on Document Server -> Graphics General Graphics -> BMAP Bitmap Images
    3.Select <IMPORT> to import bitmap image file to SAP. System will popup screen for input file information and target name.
    4.Select <Tick> After you already input data. System will upload image and return message to tell you success or fail.
    5.You can preview the picture that uploaded by select<print prv>
    If u want to store the images and retrive it from the server corresponding to the person id then just save the image by person id and code it as per the requirement.
    U can save ur images using se78 and also u can c it using TCODE AL11.By navigating thru the exact path u can get the images.

  • How to save image to local machine

    how to save my drawing (image or movieclips) to my local sytem without any server side script . i m using player 10. Please share some example

    I don't think that will bwe possible
    As that will be a hack in terms of an internet user.
    However usual solution to this is save your file at server and give user a bitton or some interface to download it

  • How to save Image from binding FlipView?

    I bind 4 images in my FlipView, how save an binding Image to Picture Library;
    <FlipView Name="display1"  ItemsSource="{Binding}" Foreground="#FFE6D52E" HorizontalAlignment="Center" VerticalAlignment="Center           
                <FlipView.ItemTemplate>
                    <DataTemplate>                  
                                <Image x:Name="image" Source="{Binding  Path=Image}" Stretch="UniformToFill"/>                
                    </DataTemplate>
                </FlipView.ItemTemplate>
            </FlipView>
    private void SaveImage_Click(object sender, RoutedEventArgs e)
                  var img = display1.SelectedItem as WriteableBitmap;
                           StorageFolder appfolder = await   KnownFolders.PicturesLibrary.CreateFolderAsync("myimage",          
    CreationCollisionOption.OpenIfExists);
            StorageFile myFile = await appfolder.CreateFolderAsync("imge1.jpg", CreationCollisionOption.ReplaceExisting);    
            img.Invalidate();
            using(Stream strem = await myFile.OpenStreamForWriteAsync())
                img.Savejpeg(strem, img.PixelWidth, img.PixelHeight, 0, 100);
    //for me it is  hard to save binding files,I cant save any image

    Hi Icce cage,
    Per my understanding, you bind the path of image to Image control, so you get image path string from display1.SelectItem property. Try finding Image from this path in installation folder and then copy it to Picture library. Please try the following code
    snippet.
    Custom class to hold the image object.
    public class CustomClass
    public string ImagePath { get; set; }
    public string ImageName { get; set; }
    Initial image sources.
    private void Page_Loaded(object sender, RoutedEventArgs e)
    images = new System.Collections.ObjectModel.ObservableCollection<CustomClass>();
    images.Add(new CustomClass() { ImagePath = "/Images/1.png", ImageName = "1.png" });
    images.Add(new CustomClass() { ImagePath = "/Images/2.png", ImageName = "2.png" });
    images.Add(new CustomClass() { ImagePath = "/Images/3.png", ImageName = "3.png" });
    images.Add(new CustomClass() { ImagePath = "/Images/4.png", ImageName = "4.png" });
    images.Add(new CustomClass() { ImagePath = "/Images/5.png", ImageName = "5.png" });
    display1.ItemsSource = images;
    XAML.
    <FlipView RightTapped="display1_RightTapped" Name="display1" Foreground="#FFE6D52E" HorizontalAlignment="Center" VerticalAlignment="Center" >
    <FlipView.ItemTemplate>
    <DataTemplate>
    <Image x:Name="image" Source="{Binding Path=ImagePath}" Stretch="UniformToFill"/>
    </DataTemplate>
    </FlipView.ItemTemplate>
    </FlipView>
    Save image to picture library.
    private async void display1_RightTapped(object sender, RightTappedRoutedEventArgs e)
    CustomClass data = display1.SelectedItem as CustomClass;
    if (data!=null)
    var installation = Windows.ApplicationModel.Package.Current.InstalledLocation;
    var imagesfolder =await installation.GetFolderAsync("Images");
    var file = await imagesfolder.GetFileAsync(data.ImageName);
    await file.CopyAsync(KnownFolders.PicturesLibrary);
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate
    the survey.

  • How to "Save Image" directly instead of "Save Image As"?

    Is there anyway or option to directly save images instead of having to click "save image as" then go into the popup to save the image location? Thank you!

    Gingerbread Man made good suggestions.
    However you still must "save as" something even if "unnamed001". Windows requires a name and location for each file (whether an image or other file) saved. You can have the same file name in different directories (folders).
    You can copy and paste images without saving, in some applications.

  • How to save image from email to iPhoto

    trying to save image attachment from email to iPhoto

    What is the problem? What does not work?
    Either drag the attachment from the mail to the iPhoto con in the Dock, or ctrl-click the attachment and use the option "Export to iPhoto" from the pop-up menu (in Mail in MacOS X 10.10). Don't remember, if this worked in Mail in Mac OS X (10.5.8), as your signature is showing.

  • Problem with how FeuerFuchs saves images

    FeuerFuchs presently seems to work like this. You load a page displaying an image or images. You like one or more of them and you want to save them. Each time you tell FeuerFuchs to save an image, instead of copying that image from wherever it's stored in order to display it on your screen to the folder you want to save it to, FeuerFuchs re-downloads that image.
    Can someone please tell me why FeuerFuchs is programmed to re-download images it's told to save instead of copying them from wherever they're stored in order to display it on the screen? It seems like that only serves to increase bandwidth usage.

    I've got that and it's great for if I want to save all the images from one or more tabs. But it only saves images from entire tabs instead of one out of several images in a tab and the treeview navigation is slower than using the shortcuts I use to jump from one folder to the next.

  • Newbie question - how to save images out of an fla file

    I have what I'm sure is a very basic flash question. I have a flash movie (swf) and the accompanying fla file. I can open the fla file, and see all the images used in the file (symbols in the library), but how can I export or save one of these images separately from flash?

    you can right click, copy an image and then paste it into your choice of photoediting software.

  • How to save image which is inside an applet?

    In my web application, I am displaying some graphs using applet. I wish to let the user save the graphs as images from the browser.
    I would really appreciate if somebody could inform me about this.
    Thanks
    Sachin

    A couple of things...
    1) You will need to sign your applet afterwards, otherwise the user will not be able to save the graphic to their hard drive due to the Java security policy.
    2) I did something similar, a code snippet is below. Mine was a Servlet version though, and sent the buffered stream to a JSP page where it was displayed as a graphic. You can figure out how to modify this so that it goes to a File stream instead... You will
    OutputStream stream;
    BufferedImage bi = new BufferedImage(pieValueObject.getCanvasWidth(),                          pieValueObject.getCanvasHeight(),
    BufferedImage.TYPE_BYTE_INDEXED);
    Graphics2D graphics = (Graphics2D)bi.createGraphics();
    // paint all your stuff on the graphics object created above
    // use a JPEG encoder to actually take what is on the graphics
    // object inside the BufferedImage, and encode it to the stream.
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(stream);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(1.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(bi);
    // Your graphic is now in the Output stream.

  • How To Save Image Trace

    I've created an 16 colour vector from an image, it appears "smooth" until I drop it into Powerpoint and it appears with all of the paths outlined. I imported into open office, right clicked and selected "break". This appeared to smooth out the image again but when it finished it appeared with every outline again. Converted to .emf, don;t know what else to do. Every option results in an image with every single area outlined. How can I save this to work with outside of Ai and have to look as it is when I save it?

    sure, here's what I'm getting as a final result and then when I open the saved file in multiple formats. As I said it makes no sense because when I "break" the image in open office it smooths it back out perfectly then goes back to outlined when completed! Really frustrating. It looks OK with the waves, but the more detailed ones aren't usable.

  • How to save image from Clipboard to disk?

    Hello;
    I want to take a screen capture of the entire screen, not only the front
    panel and save it to a file. Don't care about the image format right now.
    I am able to simulate a PrintScreen key using a call to user32.dll
    "keybd_event" in Win2K, but I am stuck here. How do I get that image that is
    now in the clipboard to disk? I have searched NI's website high and low, and
    nothing yet.
    Thanks is advance,
    /JB
    LabVIEW 6.1

    I've kind of done it "programmatically".... using the "system exec.vi" I've
    started mspaint.exe... then, I paste the image and save it to disk (too bad
    the last two steps are manually done!!!)
    The limited documentation on System Exec says it has a Standard Input
    terminal... but, I haven't figured out how to programmatically send CTRL-V
    or ALT-E to the MSPAINT application as command inputs...
    Any further ideas?
    Bill
    Jimmy Brain wrote in message
    news:[email protected]..
    > Thanks Labviewguru, but those examples deal with copying text to/from
    > clipboard.
    > There was an example from a shareware program, but it does not allow
    > to save the image. The links to register it at the his website
    are
    > dead also.
    >
    > Nobody here has ever had the need to copy programmaticaly an image in
    > the clipboard and save it to disk?
    >
    > I know that IMAQ Vision can do it, but I do not have that.
    >
    > PS: I found this OCX ( http://www.simtel.net/pub/pd/57740.html ) on
    > the web that does this, but I haven't been able to get it to work from
    > inside LabVIEW. The Visual Basic example works, but I can't seem to
    > replicate the call to this OCX in LabVIEW.
    > I am mostly trying to learn on my own, that is why I want to much to
    > solve this.
    >
    > Thanks in advance for any help out there. I have become frustrated
    > with this little problem. I know someone might have an easy answer,
    > but I haven't found it yet. Thanks!!!! :-)
    > /JB
    > LabVIEW 6.1

Maybe you are looking for