Converting an image object to  bufferedimage object

Hi does anyone know how to convert an Image obj to a BufferedImage obj without casting...
I have generated an image in an applet by rescaling a larger image but i cannot cast it to a BufferedImage as it was declared as an image type...
thx

Image img = setupImage(); // or however you set up your Image
BufferedImage bimg = new BufferedImage(img.getWidth(), img.getHeight, BufferedImage.TYPE_ARGB);
Graphics g = bimg.getGraphics();
g.drawImage(img, 0, 0, null);

Similar Messages

  • Converting an Image object to a BufferedImage object?

    I have a BufferedImage object, bi, which I want to resize, hence:
    Image image = bi.getScaledInstance(400, 300, Image.SCALE_DEFAULT);
    Next I want to encode the resized image to JPEG format. The problem is that inorder to use the JPEGImageEncoder.encode() method, I need to pass it a BufferedImage object. I have looked through the API and cant see a way of converting the Image object to a BufferedImage object.
    Can anyone shed some light on this problem?
    Any help will be much appreciated.

    I copied + pasted the code from:
    http://java.sun.com/docs/books/tutorial/2d/problems/ind
    x.html :-)
    So you propably could use :
    int width = 400;
    int height = 300;
    Image image = bi.getScaledInstance(width, height,
    Image.SCALE_DEFAULT);
    BufferedImage bi = new BufferedImage(width, height,
    BufferedImage.TYPE_INT_RGB);
    Graphics2D biContext = bi.createGraphics();
    biContext.drawImage(img, 0, 0, null);Greets
    PuceThis works fine; but has anybody else noticed this takes an unreasonable amount of time? How to get around this?

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • How to convert a Image object to byte Array?

    Who can tell me, how to convert Image object to byte Array?
    Example:
    public byte[] convertImage(Image img) {
    byte[] b = new byte...........
    return b;

    Hello,
    any way would suit me, I just need a way to convert Image or BufferedImage to a byte[], so that I can save them. Actually I need to save both jpg and gif files without using any 3rd party classes. Please help me out.
    thanx and best wishes

  • Converting JPanels as image objects

    hi,
    i am having problem in converting a JPanel object which consits of some
    JLabels and images into a Image Object. Actually i want to save the JPanel as
    a jpg file which i will do with jped encoder.
    so please help me in converting this JPanel to image object

    assuming the panel is showing.... (if not, you might need to user getPreferredSize() and setVisible before paint()).
    Dimension size = panel.getSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bi.createGraphics();
    comp.paint(g2d);

  • Plz Help!!! Have to  convert an paint object to image

    Hi.I am new to Jave and am developing an application
    which has to send painted shapes(using SWING) to a mail id.
    I think it can be done in two steps
    1) Converting the paint objects to images.
    2} sending the image
    However I don't have a clue regarding the first step
    and have only a rough idea about the 2nd.
    Please suggest a solution.
    Thanks

    hi,
    you can try using the Robot call and calling the screencapture method, giving the the correct parameter values should allow it to get the image you want only, this will return a BufferedImage object, you can search the forums on how to convert a BufferedImage object to an image there are plently of examples floating around.

  • Converting a image file (JPG or BMP or any other) to an Image object

    Hello, does anyone have an idea of how I could convert a image file (JPG, BMP, GIF or any other) or even a Corel Draw (.CDR) file to a java Image object?
    Thanks in advance
    Wilson

    Demo:
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class ImageResized {
        public static void main(String[] args) throws IOException {
            URL url = new URL("http://today.java.net/jag/bio/JagHeadshot.jpg");
            BufferedImage image = ImageIO.read(url);
            Icon icon = new ImageIcon(image);
            JLabel label = new JLabel(icon);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Outputting an Image object to jpg or png

    Hello,
    I have an Image object in my code that is output from another java object. The other java object is from a libarary of GIS classes known as JLOOX.
    Anyway, I have an Image stored in the Image object but want to output it to a file. I was looking at the Java Almanac and saw a page http://javaalmanac.com/egs/javax.imageio/Graphic2File.html However, this uses a BufferedImage object.
    Is there anything I can do with the Image object to output to a file? Can I convert it to a BufferedImage somehow?

    BufferedImage b = new BufferedImage(
    source.getWidth(), source.getHeight(),
    BufferedImage.TYPE_INT_ARGB  );
    b.getGraphics().drawImage( 0, 0, source, null );
    ImageIO.write( b, "png" );Thanks, but I have an Image object. How do I write the Image object to ImageIo.write?

  • How to save image using an image object in servlet on web server

    I'll be very thankful to anyone who helps me in this matter.
    i developed an applet which draws on a buffered image.
    now i want to save this buffered image as a jpg image on the web server.
    i know i have to use servlets or jsp for this.
    but i want to use servlet for specific reasons.
    can anyone plz provide me the code for taking an image object from an applet and saving it thru servlet.
    i need this solution as soon as possible.
    thanks in advance.

    Take a look around for URLConnection, and Applet to Servlet communication (also check the [url http://forum.java.sun.com/forum.jsp?forum=33]Servlet forum).
    Basic concepts will be to open a URLConnection to the URL mapped on your server for the servlet, then send the image, byte by byte, to the servlet, then ask for a reply from the servlet.
    Once asked for a reply the servlet will need to take the image sent to it (hopefully via an HTTP post) and copy it to a location on disk. (You could have a parameter to the request that tells you want to name the file...)
    As for the converting buffered image to JPEG, I haven't done this before, but I know others have. You can look around (more likely to find it in the [url http://forum.java.sun.com/forum.jsp?forum=31]Java Programing[ul] forum) for the code needed.

  • Kelby shows CS 6 converting to smart object before using Liquify

    In Kelby's "Hidden Gems" of CS6, he converts the image to a smart object using the filter menu "convert for smart objects" before he uses the Liquify filter, thus adding a Liquify mask and the ability to go back and edit Liqify. When I open a Raw file and convert to smart object, it greys out the Liquify filter. Liquify is only available before adding the smart filter. What's wrong with this? I'm on a Mac 10.8.2

    Only the Creative Cloud Photoshop CS6 v13.1 has Smart Filter enabled Liquify and Blur Gallery. (However, apparently, 13.1 has an additional payload of bugs and broken functionality.)

  • Iphone get photo as image object

    hi,
    I am new to Mac os programming. I am testing iphone programming. I would like to access the photo saved in iphone as an bitmap image object. How can I do it?
    I know I can use UIImagePickerController, but not sure how to get the image object and access every pixel after that.
    Thank you very mcuh.
    af

    The UIImagePickerControllerDelegate method didFinishPickingImage is called once the user chooses a photo. This contains the UIImage. UIImages can be converted
    http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageP ickerControllerDelegateProtocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#// appleref/occ/intfm/UIImagePickerControllerDelegate/imagePickerController:didFinishPic kingImage:editingInfo:

  • Converting a class object back to a .class file

    Hi,
    How can i convert a class object back to a .class file ? Thanks

    any pointers on how to do it then ? i don't have
    access to the native codeIf I have understood you correctly, you have native code that generates bytecode. Currently you load the class this bytecode represents right into the classloader, but you want to save it to disk as a .class file. Right?
    If so, you just have to get hold of that bytecode before it "disappears" into the classloader, and save it to disk. How you can best do this depends on exactly how you communicate with that native code.
    If I have misunderstood your problem (and that's not unlikely), please try to be clearer.

  • How can I convert an Image ( or BufferedImage ) to Base64 format ?

    Hi folks...
    How can I convert an Image, or BufferedImage, to the Base64 format ?
    The image that I want to convert, I get from the webCam connected to the computer...
    Anyone can help me ?
    Rodrigo Kerkhoff

    I suggest you read this thread concerning this:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=477461
    Failing that, Google is your friend.
    Good luck!

  • How to Compress non-image object in Acrobat 9 Pro/Acrobat X Pro

    Hi,
    I am newbie and don't know where to post this question exactly. Forgive me if I am incorrect.
    How can we compress "non-image object" in "Acrobat 9 Pro/Acrobat X Pro"
    Thanks in advance for your suggestion & help.
    Thanks & Regards,
    Raja. S

    Thanks for the reply.
    I want to compress the "non-image" objects (i.e pagragraph contents and not images) for the entire PDF file in the "Acrobat pro X" application manually and not with the tool.
    Please share me if you have any idea on this.
    Thanks,
    Raja. S

  • Convert a calendar object to a date object

    hi all...i use a calendar to select date and i want to convert the Calendar object returned to a date object ..how could i do that ?? i use the following lines of code but the Date object returned is not correct ..i mean it's not the one i chose from the calendar
    Date selectedDate=new Date();
    selectedDate=(calendar1.getTime());
    Any one could help....thank you

    Show us the code where you set the calendar to your desired value. Calendar1.getTime()
    should return the relevant date.

Maybe you are looking for

  • How to set up an external Hard Drive as a cloud folder for remote users?

    I have an external HD connected to my MacBook Air that I need two other people in my company to be able to access from far away cities. I'd like to know if there is a way of them having a folder in finder that goes straight to this external, similar

  • W520 on Series 3 Mini-Dock - Cooling Pad?

    Does anyone have a good solution for a cooling pad which integrates well with the W520 attached to the Series 3 Mini-Dock  (170Watt)?  Did a search on cooling pads for this configuration and couldn't find a solution.  I just received my new W520 and

  • How to use indexof  for LinkedList

    i am not getting how to use the function "public int indexOf(Object o)" described here http://java.sun.com/javase/6/docs/api/java/util/LinkedList.html#indexOf(java.lang.Object) in my program to find the index of either a or b the code is import java.

  • Why are signatures from .HTML files no longer appended (v31.1.0)?

    I have been using Thunderbird for some six months now. At the outset I set up an .HTML signature file for each of the accounts, and up to now this option has functioned well. At some time over the last couple of days the feature stopped working --no

  • My website has stopped displaying in IE but displays okay in Mozilla

    I added Google Analytics to the web site and the web site cannot be displayed by IE in preview mode or in the live mode. The web site displays okay in Mozilla. I have removed the analytics code but the problem persists. Thanks.