Generate a JPEG file

In my project, I need to generate a JPEG file in using a screen capture that I obtain with the use of a Robot.
I have the following code :
public static BufferedImage getScreenCapture(int x, int y, int width, int height)
     Robot            robot            = null;
     Rectangle        rectangle        = null;
     BufferedImage    bufferedImage    = null;
     try
          robot = new Robot();
          rectangle     = new Rectangle(x, y, width, height);
          bufferedImage = robot.createScreenCapture(rectangle);
     catch(Exception e)
          e.printStackTrace();
     finally
          return bufferedImage;
}After the load of my buffered image, I need to generate the JPEG file. So, I use the following code :
try
     JPEGEncodeParam  jpegEncodeParam  = null;
     JPEGImageEncoder jpegImageEncoder = null;
     BufferedImage bufferedImage = ImageManager.getScreenCapture(0, 0, 100, 100);
     jpegEncodeParam  = JPEGCodec.getDefaultJPEGEncodeParam(bufferedImage);
     jpegImageEncoder = JPEGCodec.createJPEGEncoder(new FileOutputStream( new File("C:\\test.jpg") ), jpegEncodeParam);
catch(Exception e)
     e.printStackTrace();
}The result of this is that I've got a jpeg file empty.
I'm novice in the use of the Codec, so my question is maybe stupid but I don't understand where is my error.
If someone can help me.

I Don't understand the codec either and have ahard time understanding the docs on JAI and ImageIO
compared to the rest of Java.
However the below code does write out a JPEG file, that can be viewed by Java and other Image Viewers,.
I'd say check if your "Robot" ???? is actually getting an Image, by subclasssing ImageIcon to show a
BufferedImage and sticking that on A JLabel ??
I'd like to see the 'correct' way to do this so you can set all the parameters, but if you just want a jpeg file adapt this:
Err it loads in a tif image off disk and writes it out in all the supported formats
( at least I think it does )
import javax.imageio.*;
import java.awt.Dimension;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.image.*;
public class ReadWriteTest
     private String ErrorString;
     private boolean SuccessStatus;
     private BufferedImage ImageStore;
     private File f;
     public ReadWriteTest()
          ErrorString = "";
          SuccessStatus = true;                    // Default set Success
          String filename = "MyPic.tif";
          ImageStore = null;
          if( filename == null )
               ErrorString = "No FileName";
               SuccessStatus = false;
               return;
          f = new File( filename );
          if(!readInFile( f ))
               return;
          String[] Names = ImageIO.getWriterFormatNames();
          System.out.println("Image Types Write Test" );
          for( int i = 0 ; i < Names.length ; i++ )
               System.out.println("Type: " + Names[i] +"    ");
               filename = "ImageDump/Test." + Names;
               System.out.println( filename );
               f = new File( filename );
               System.out.println("Attempting to Write Image Type: " + Names[i] );
               try
                    ImageIO.write(ImageStore, Names[i], f);
               catch( IOException IOE)
                    System.out.println("IO ERROR Writing Image : FAIL" );
     public static void main( String[] args )
          ReadWriteTest T = new ReadWriteTest();
     private boolean readInFile( File F )
          if( !F.exists() )
               ErrorString = "File Doesn't Exist";
               SuccessStatus = false;               
               return false;
          if( !F.canRead() )
               ErrorString = "Cannot Read() File";
               SuccessStatus = false;               
               return false;
               javax.imageio stuff
     //     ImageIO.scanForPlugins();
          try
               System.out.println("Attempting to decode Image");
               ImageStore = ImageIO.read( F );               //Magically create Buffered Image from supported 'Readers'
          catch( IOException IOE )
               ErrorString = "IO Error Decoding Image";
               SuccessStatus = false;
               return false;
          catch( IllegalArgumentException IAE )
               ErrorString = "Failure By Installed Reader: " + IAE.getMessage();
               SuccessStatus = false;
               return false;
          if( ImageStore == null )
               ErrorString = "Could Not Decode Image";
               SuccessStatus = false;
               return false;
          return true;

Similar Messages

  • Generating a Movie File from a List of (JPEG) Images

    Hi All!
    I was trying this example:
    Generating a Movie File from a List of (JPEG) Images
    http://java.sun.com/products/java-media/jmf/2.1.1/solutions/JpegImagesToMovie.java
    I was using the following command line with the following output:
    root - /home/robertmarkbram/java/jmf/classes
    $java JpegImagesToMovie -w 320 -h 240 -f 1\
    -o file:///home/robertmarkbram/CoolCampus/media/jpgOut.mov\
    file:///BigBrain3/pics/breakfast.jpg\
    file:///BigBrain3/pics/eating.jpg\
    file:///BigBrain3/pics/howto.jpg\
    file:///BigBrain3/pics/jupiterp_cassini_full.jpg\
    file:///BigBrain3/pics/jupiterp_cassini.jpg\
    file:///BigBrain3/pics/spocamok.jpg- create processor for the image datasource ...
    Setting the track format to: JPEG
    - create DataSink for: file:///home/robertmarkbram/CoolCampus/media/jpgOut.mov
    start processing...
    - reading image file: file:///BigBrain3/pics/breakfast.jpg
    - reading image file: file:///BigBrain3/pics/eating.jpg
    - reading image file: file:///BigBrain3/pics/howto.jpg
    - reading image file: file:///BigBrain3/pics/jupiterp_cassini_full.jpg
    - reading image file: file:///BigBrain3/pics/jupiterp_cassini.jpg
    - reading image file: file:///BigBrain3/pics/spocamok.jpg
    Done reading all images.
    java.lang.NullPointerException
    at com.sun.media.multiplexer.video.QuicktimeMux.writeVideoSampleDescription(QuicktimeMux.java:936)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeSTSD(QuicktimeMux.java:925)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeSTBL(QuicktimeMux.java:905)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMINF(QuicktimeMux.java:806)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMDIA(QuicktimeMux.java:727)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeTRAK(QuicktimeMux.java:644)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMOOV(QuicktimeMux.java:582)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeFooter(QuicktimeMux.java:519)
    at com.sun.media.multiplexer.BasicMux.close(BasicMux.java:142)
    at com.sun.media.BasicMuxModule.doClose(BasicMuxModule.java:172)
    at com.sun.media.PlaybackEngine.doClose(PlaybackEngine.java:872)
    at com.sun.media.BasicController.close(BasicController.java:261)
    at com.sun.media.BasicPlayer.doClose(BasicPlayer.java:229)
    at com.sun.media.BasicController.close(BasicController.java:261)
    at JpegImagesToMovie.controllerUpdate(JpegImagesToMovie.java:215)
    at com.sun.media.BasicController.dispatchEvent(BasicController.java:1254)
    at com.sun.media.SendEventQueue.processEvent(BasicController.java:1286)
    at com.sun.media.util.ThreadedEventQueue.dispatchEvents(ThreadedEventQueue.java:65)
    at com.sun.media.util.ThreadedEventQueue.run(ThreadedEventQueue.java:92)
    Can anyone tell me what this error message means?
    Thanks for any advice!
    Rob
    :)

    I think it does that for QuickTime if you don't define the lineStride value in the VideoFormat (lineStride = pixelStride * width).

  • Preventing .jpeg files from being generated/saved

    I'm trying to capture a graph on the front panel into an .html file using the case structure in the attached .vi.  The case structure works but I keep getting  a jpeg file in the form of CT0327xxxxxxx.jpeg saved in the C:\vibration data directory each time a capture is performed.  How do I keep this image from either being generated or saved?  Thanks in advance.
    Message Edited by GSO on 09-12-2007 10:33 AM

    Sorry. Here it is.
    Message Edited by Dennis Knutson on 09-12-2007 11:18 AM
    Attachments:
    Append Image.PNG ‏46 KB

  • Reading .jpeg files in FILE or FTP adapter

    Hii
    I have to send .jpeg files at regular intervals using BPEL.
    I read about Base64 data type. I tried to create File Adapter and FTP adapter. I specified the folder location and *.jpeg as file pattern. I have made schema to opaque.
    But neither File or FTP adatper are picking up the file from specified directory. As per my plan, once I will get Opaque schema in BPEL, I will use Base64 encoding to get the data as string and to pass it to the endpoints.
    Any idea what I need to do in order to read .jpeg files.
    Any help is highly appreciated.

    Thanks for the help. Actually, I am following the similar process as given in "Tutorial 11 : File DB Integrations – Handling of opaque data types".
    I'm using SOA Suite 10.1.3.3; the .jpeg file is being picked up by the File Adapter, but failing to create BPEL instance with the following log details :
    +"<2009-03-06 17:02:13,053> <ERROR> <default.collaxa.cube> <BaseCubeSessionBean::logError> Error while invoking bean "cube delivery": [com.collaxa.cube.engine.delivery.CorrelationResolutionException: Correlation definition not registered.+
    +The correlation set definition for operation "ReadJPEGOp", process "SyncBase64BPELProcess", has not been registered with the process domain.+
    +Please try to redeploy your process to the process domain.+
    +]+
    +ORABPEL-03802+
    +Correlation definition not registered.+
    +The correlation set definition for operation "ReadJPEGOp", process "SyncBase64BPELProcess", has not been registered with the process domain.+
    +Please try to redeploy your process to the process domain."+
    I have deployed the process multiple times on two different SOA Suite Server 10133, but getting the similar logs. The file is being picked up but not generating BPEL instance.
    Any idea ???

  • My report contains a BLOB (image), why it can't generate an XML file?

    Hi guys,
    I created a report (Purchase Order) and it has a Signature field.
    which is a BLOB column of an image (.JPEG) of the signature of the Purchase Order Approver.
    When i run the report in the report builder its working and it shows the image of the signature.
    BUT when i try to generate xml file to use it for the XML Publisher, it generates an xml file with error. which can't be loaded into the .rtf file.
    i Googled around and it seems that there are limitations in XML Publisher that can not load a BLOB or LONG RAW fields.
    So Please guys i need your help! what can i do now ?
    They need the Purchase Order in a custom PDF format, which i can only make it with XML Publisher.
    Best Regards,

    Hello,
    For questions about BI Publisher (Formelly XML Publisher) :
    BI Publisher
    Regards

  • How to generate a pdf file using javascript?

    I would like to generate a pdf file having images in it using javascript. I tried jsPDF but getting some exceptions like
    Uncaught ReferenceError: pageWidth is not defined,
    fail to load pdf document
    Could anyone show me some pointers?
    Thank You
    Rahul

    Here is my code
    var myImg=new Image();
      myImg.src=arrData['employee'][1]['Image'];
      myImg.crossOrigin ="Anonymous";
       var imgData = this.getBase64Image(myImg);
       var doc = new jsPDF();
       doc.setFontSize(40);
       doc.text(35, 25, "Test Image");
       doc.addImage(myImg, 'JPEG', 15, 40, 180, 160);
       doc.save("sample1.pdf");
    I'm receiving the following error at 'addImage' function.
    Uncaught Error: getJpegSize could not find the size of the image
    Could you please help in pointing out where am I going wrong.
    Thank You

  • IMAQ Write JPEG File Error

    Hi,
    I am trying to save the image file captured by a camera (.tiff) to JPEG file, but it came up with an error. Can anyone tell me how to fix this issue?
    The sample VI and the TIFF image file are attached. Thanks a lot.
    Jane
    Solved!
    Go to Solution.
    Attachments:
    SaveJPEG.vi ‏47 KB
    SaveJPEG.vi ‏47 KB
    IR_Image.zip ‏443 KB

    The VI "IMAQ Dispose" is not used immediately after creating the image with the VI "IMAQ Create" and is closing a session you will process later, you must also change the location at which to save the image, because to the location "C: \" and "C: \ temp \" often generates problems with operating system permissions.
    Regards.
    Jonathan Cruz
    CHALLENGER
    K U D O S __ B I E N V E N I D O S

  • Why is Lightroom5 copying both RAW and Jpeg files into the destination folder ?

    Hi all Lightroom experts,
    I want to copy the RAW files from my SD csrd to my Drobo harddisk. And everytime I did that, Lightroom copied BOTH the raw & jpeg files
    How do I instruct Lightroom to copy only the RAW files ?
    Just to disgress a bit, in fact the same problem happens in Adobe Bridge despite me selecting only the RAW files to be copied but it always copied both !!
    Any tips ?
    Thanks

    dj_paige wrote:
    You can tell Lightroom to treat JPGs next to RAW as separate photos, or treat the JPG as a sidecar file using the instructions here:
    Lightroom Help | Set import preferences
    If the JPG is a sidecar file, the JPG is still imported but doesn't show in your Library module.
    If you really don't want to import the JPGs, you'd have to select the RAWs but not the JPGs in the Import dialog box; or import them all and then delete the JPGs from Lightroom and your hard disk (easier, but takes a little longer); or don't shoot RAW+JPG
    Thanks dj_paige and F.MacLion for the solution.
    Can I check, if i tick the the check-box and ask LR5 to treat the jpeg as a separate file, FR5 won't import the jpeg files (which is what I wanted) but will LR5 still generate a sidecar file for each of my RAW files ? (I hope it does)
    Thanks

  • How do I find BOTH the raw and the cameras jpeg files?

    I've got Aperture 3 importing raw plus jpegs from my Nikon D600 camera. The D600 produces amazing jpegs!
    Aperture is set to use the raw file as the master.
    I'd hoped that I'd have access to both the raw AND the camera jpeg but I only see the raw file and as soon as I open it, the cameras jpeg is replaced by something that aperture generates. It's quite frustrating because the jpegs from my Nikon look fantastic but only for a couple of seconds before aperture replaces them with a horrible, jpeg.
    I want to have access to both the camera's jpeg and the raw file. Aperture's jpegs just aren't that good compared to the Nikon original jpegs. Not even close!
    Is there any way that I can get back my Nikon camera's jpegs or are they gone, forever?
    Thanks in advance!

    Roy Martin German wrote:
    For some unknown reason, although I can see both the "Use JPEG as Original" and the "Use RAW as Original", both of these menu items are grayed out?
    A couple of ways this can happen is (1) if only one format is actually on the  camera's card (i.e., the camera's Quality setting is incorrect), or (2) if "Import RAW files only" or "Import JPEG files only" was selected in the RAW+JPEG Pairs panel in the import dialog. So (1) are you sure the card contains RAW and JPEG images (e.g., have you looked at it with Finder), and (2) what setting was used during import?
    Roy Martin German wrote:
    but I only see the raw file and as soon as I open it, the cameras jpeg is replaced by something that aperture generates.
    Not sure what you mean by this statement. By design Aperture doesn't "replace" anything. Can you clarify?

  • Creating GIF or JPEG files

    Is it possible to render a graphic object into a GIF or JPEG file and save it in a Java application?
    Thanks.
    Pradeep Gupta
    518-383-1167
    [email protected]

    For JPEG:
    1) Try JAI (http://java.sun.com/products/java-media/jai/) or the Java Image I/O from JDK 1.4.
    2) Try PJA (www.eteks.com)
    There is a pitfall if you want to do imaging in a Unix/Linux machine and the Java program can not access a X Server (maybe the machine is not running X). In this case you must install a "fake X Server", or use PJA.
    For GIF:
    Due to LZW patent problems with GIF compression the packages that generate GIF files have(had) to get a Unisys license.

  • JPEG files from the PhotoLibrary and from the UIPasteboard

    Hello all,
    Does anyone happen to know whether JPG files can be fetched directly from the iPhone's photo album?
    My App. knows the name of the file "IMG_0322.JPG", for example, but I can't seem to find the way to generate the Path to get to the directory to read the file.
    ===================
    Another issue which is actually related:
    I am successfully able to detect a that a JPEG file is on the UIPasteboard, but I am at a loss as to how to convert it to a UIImage.
    If I do the following:
    NSData * dataObject = (NSData *) UIImageJPEGRepresentation([dict valueForKey: @"public.jpeg"], 0.8);
    ...and if dataObject has data, then there was a JPEG file in the dictionary.
    ...but then if I do this:
    UIImage * imgD = [UIImage imageWithData: dataObject];
    CGSize imSize = imgD.size;
    ....imSize shows a size of 2,048 x 1536 which is totally bogus.
    Any help would really be appreciated.
    -- thanks very much in advance rick s
    How can I convert a JPG file in my sandbox (bundle) to an UIImage object?

    Never tried it before...
    Is this what you are talking about?
    http://www.oracle-base.com/articles/10g/file-upload-download-procedures-10g.php
    Cheers,
    Manik.

  • Generate xml source file for Oracle Order Capture Print Quote

    Hi,
    I am new to xml and need to work on creating templates for Print Quote.
    I am trying to generate the xml source file for which I enabled the report in system administrator and set the output to XML and assigned to Quoting Reports responsiblity. I then assigned XML Report Publisher to the same responsiblity.
    I ran the report (Print Quote) and then I am trying to run the XML Report Publisher but I cannot get the request id in the list of values.
    I am able to generate xml source file for other reports like Printed Purchase Order etc.,
    The view output for the (Print Quote) report is as follows:
    <?xml version="1.0" ?>
    - <!-- Generated by Oracle Reports version 6.0.8.26.0
    -->
    <ASOPQTER />
    How do I get the xml source file? Or are there seeded templates that I can use to create more templates? Any help would be appreciated. Thanks Ravi

    Hi, I am in the same position - did this issue ever ger resolved by anyone. I have done a few XMLP reports successfully now using the Word add-in, but customising the Quote output differs from other standard reports.
    If you look at the data definition for Quote it is a 'dummy' definition and has no XML file attached. Does anyone know how I can get the XML format for the report output?
    Also the template uses XSL-FO ?!?!?! rather than RTF - not sure how to work with this, the Oracle docs are not very helpful in this regard either.
    Has anyone successfully managed to customise the Quote print report? Many thanks,
    Roger

  • How to view .jpeg files in Yosemite

    Am using Yosemite (10.10.2) on my iMac and want to view rather old .jpeg photos. When I attempt to open them, I get an error message saying Photoshop 3.0 is required. When the file titles are displayed in Finder, I can see the little-bitty picture, so I think the Mac knows the picture is there, just reluctant to let me view it.  (I tried using Preview and iPhoto and neither one works for this.)
    Is there some way to view these photos with the existing Mac programs?
    Thank you,
    TBS2

    Thanks for all the replies. I tried to respond to everyone individually, but the rules say I can only post content every 30 seconds. Hence this combined reply.
    Don't have "Quick Look" on my iMac. I did use the "Get Info" option to open all .jpeg files with Preview. Didn't work. Did try to open the files from within Preview using the "Open file" option.
    Tried opening with Firefox (thanks to whomever posted that hint somewhere on the blog) and the Firefox error message says there is an error in the file.
    I am able to open other .jpeg files with Preview, so I am now of the belief there is a problem with the file, not with how my system is handling it.
    Suppose a "fixer" of some kind is in order, but I don't know what that is!
    Thanks again for everyones help.
    TBS2

  • RAW files converted to JPEG files on my mac can't be seen by my customer who has a PC: WHY?

    I have been using Adobe CS5 for over a year now but only recently discovered how Adobe Bridge helps with work flow and post processing. My first time using Bridge I put all my RAW NEF files into folders and, after processing them in Photoshop, put all the JPEG files into a seperate folder. Before sending said JPEG images to my client, I batch renamed them to make sure the image file numbers were in the proper consecutive order. My client, who is a PC user, received these images and said she was unable to view them. Her computer system isn't outdated and I'm not sure what the issue is. I'm wondering if there was a formating change that happened when I did the batch rename or if the problem is Adobe Bridge altogether? I did all these on my Mac Book Pro which is only a year old..What am I missing??

    Did each image have its .jpg extension? i think Windows likes to see the extension, Macs don't care.

  • Moved jpeg files to other folder, now iPhoto can't find them

    I dragged/dropped some original jpeg files into a new folder to aggregate certain files together, but since they are now in a different folder iPhoto 9 can't find them. The thumbnails in iPhoto still remain, but results in the large black/grey "!" when I try to open them. I'd rather not rebuild the enormity of my entire photo library over this, so is there some other way to re-link thumbnails to files?
    iTunes makes this easy with music. When I click on a file name and it can't find the file, it offers to allow me to locate the file myself, and then it re-establishes the link between the iTunes library item and the file. No problem.
    How does one go about doing this in iPhoto for, say, a couple of dozen files without having to start over with an ENTIRE rebuild? I know exactly where the files are, and it seems ridiculous that iPhoto isn't equipped to track the whereabouts of an unchanged file that's simply been dragged from one folder to another.

    Did you do the moving of the image file in the Finder or do you have a reference library as asked by Larry? In either case moving the files is a recipe for disaster as you've found out. You must either move the files back to their original locations or try to get those photos back into iPhoto as follows:
    1 - Find the folder you moved the files into and COPY it to the Desktop.
    2 - in iPhoto delete the photos that you're having the problems with as you normally would even though you can't see see them. Also delete all the photos that are in the folder you moved the other files into.
    3 - drag the folder on the Desktop into iPhoto to import them as one event. If you get a duplicate warning I'd let it import the duplicate and use Duplicate Annihilator to find them so you can cull out the duplicate you don't want.
    Other than that you might have to start over from scratch as follows:
    Creating a new library while preserving the Events from the original library.
    1 - Move the existing library folder to the desktop
    2 - Open the library package like this.
    3 - Launch iPhoto and, when asked, select the option to create a new library.
    4 - Drag the Originals folder from the iPhoto Library on the desktop into the open iPhoto window.
    OT

Maybe you are looking for