Saving a BufferedImage to disk in JPEG format

Hi,
How do I save a BufferedImage to disk in jpeg format. I guess I will have to use a jpeg encoder for that purpose. Where do I get free jpeg encoders ?? And using the encoders how do I write the encoded image to the disk??
Thanks in advance.
Regards
Jaydeep

I use it for saving PNG images.
You can use similar code for JPEGs.
ByteArrayOutputStream os=new ByteArrayOutputStream();
PNGCodec p=new PNGCodec();
ImageEncoder pe=p.createImageEncoder("PNG",os,null);
BufferedImage bi=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
bi.getGraphics().drawImage(icon.getImage(),0,0,null);
pe.encode(bi);
byte[] ba=os.toByteArray();
i use JAI library for this purpose.
best regards
Stas

Similar Messages

  • Save for web as PNG-24 with slices is saving in JPEG format!

    Hello all.
    I'm using Photoshop Extended CS6 13.0.1 x64 and when I save for web as PNG-24, all the slices from the project, the final result are JPEG format pictures. I tried the same but exporting as GIF and it keeps saving as JPEG. I tried Save As instead of Save for Web and it works, but this way I'm not saving by slice and not for web.
    Any idea why this happens?

    Found the solution. I had to select all the slices.

  • Display image in JPanel without saving any file to disk

    Hi,
    I am fetching images from database. I am saving this image, display in JPanel and delete it. But this is not actually I want.
    I wish to fetch this image as stream , store in memory and display in JPanel without saving any fiel in disk.
    I wonder if it is Possible or any used implementation that I can use in my project. Any idea or experienced knowledge is enough.
    Thanks

    In what format is the image coming to you from the database? If it's an InputStream subclass, just use javax.imageio.ImageIO:
    InputStream in = getImageInputStream();
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have beenIf you receive the image as an array of bytes, use the same method as above, but with a ByteArrayInputStream:
    byte[] imageData = getImageData();
    ByteArrayInputStream in = new ByteArrayInputStream(imageData);
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have been

  • Is there a practical size limit on JPEG format image files?

    I have noticed when working with Photoshop v7.0 on Windows XP that, when creating a JPEG format image file from a very large scanned image (more than 800 Mb, maybe), the .jpg file will usually be saved on disk at any of the possible compression ratios available, without any reported error, yet when the saved file is re-opened, an error is reported - something along the lines of "missing or corrupted end of file marker" - and the image cannot be loaded.
    If before saving the original image is substantially reduced in size, e.g. by reducing the resolution of the image, a viable JPEG format file can be created, which will subsequently load successfully, though technically with data loss.
    This appears to happen only with JPEG format files - PDF format files can be saved from the original image at similar JPEG compression ratios, without error on reloading.
    I do not know if this also occurs with any other Photoshop versions.  I am working with Adobe Photoshop v7.0 on Windows XP, although we are preparing to upgrade to CS (which version I don't know) in the near future, for different reasons to those which are detailed above.
    Does anyone know if there is a technical explanation for this behaviour?  Is there a file size limit for writing viable JPEG files (which Photoshop does not report as an error when exceeded)?
    Thanks

    Chris Cox wrote:
    Where did you get the idea that we weren't doing something about it?
    that's what I gathered from "JPEG cannot [...] in Photoshop (code difficult to replace)".
    But if you say this is in the works right now, that's good news indeed.
    Chris Cox wrote:
    And where did you get the idea that posts get deleted? (other than SPAM)
    Are you sure you're reading the same forum as the rest of us?
    That's what happened:
    The content you posted below was reported for abuse and removed by our
    moderators:
    Subject: Re: Is there a practical size limit on JPEG format image files?
    Posted: 4/29/11 9:11 AM
    Anyway, you gave an honest answer on this technical issue, Chris, and that's what counts.

  • 'Save As' to JPEG format (or to TIFF)

    The 'Save As' command produces 20 different file format options to choose from. When 'saving as' to the default PSD format, the selection is obviously quick and easy. However I mostly 'save as' to JPEG format or TIFF format and it is awkward to make the JPEG or TIFF format selections each time.
    After doing 'Save As', I have been clicking on 'Format' and then typing 'j' or 'ti' to bring up JPEG or TIFF from the menu of 20 formats to speed up the selection a little bit as compared to scrolling through the Format menu.
    But it would be much easier to have a script that could bring up a modified version of the "Save As" dialogue box so that 'Save As' to JPEG format or 'Save As' to TIFF format could be executed very efficiently and without having to wade through the clutter of the 17 other file formats in the Format menu which I hardly ever use.
    I have done a fair amount of web searching, including on ps-scripts.com, but so far without finding a good solution to this. Any help would be much appreciated.
    Of course I have thought of creating an Action (with assigned keyboard shortcut) which saves to JPEG and another Action which saves to TIFF. However, the saved file then always ends up in one location and with the same file name, therefore often requiring the additional steps of renaming and moving the file.
    Batch processing of Actions (perhaps in conjunction with the Image Processor script) is perfect for batches, especially for large batches but I was hoping for something quick and easy for saving files individually.
    Thanks!
    Geoff
    P.S. I also tried finding a way of disabling all the 'Save As' file formats which I never use so that the 'Save As' format choices would be very few (i.e. 3 or 4 instead of 20) but have had no success there.

    It's been awhile since I played with the saveAs function.
    Pretty sure you have to type the file name in the save dialog
    Here is a function I created for work.
    I removed a lot of code from it that doesn’t pertain to this topic but the code should work
    This might help you with a little more understanding and show how you can hard code where to save without even bringing up a dialog box
    saveAsPNG( filelocation + filename )// usage
    function saveAsPNG( where ){
                   var tmpFile = File(where + '.png' );
                   var pngOpts = new ExportOptionsSaveForWeb;
                        pngOpts.format = SaveDocumentType.PNG
                   //     pngOpts.PNG8 = true;
                        pngOpts.transparency = true;
                   //     pngOpts.interlaced = false;
                        pngOpts.quality = 100;
                   app.activeDocument.exportDocument(tmpFile,ExportType.SAVEFORWEB,pngOpts);
              return true;

  • How do I email a picture in iphoto in jpeg format?

    How do I email an iphoto picture in jpeg format?

    The direct way: In iPhoto get the picture/s you want on screen and click on the 'share' button in the bottom right of the window and select 'email' from the list. From the dialogue box choose a size you'd like the image to be and your email app should launch with the jpeg already included in the body of the email.
    Another way: In iPhoto select the image you want and from the File menu slect Export. Save the file to a place you can easily find it. Create an email and add the attachment from wherever you saved it.

  • Changes in line definition when converting from Freehand to jpeg format

    When I change my maps into jpeg formats, the lines change.
    e.g. a dahed line may become dashes and dots, not as they were drawn. This has happened since I had a new hard disk in my iMac.
    Can anyone help?
    Blodwin

    I would try other raster-based formats like TIF and PNG to see if the problem is there. Also does this change happen to all dashed lines or only on a certain type of line? I would try various line widths, colors, straight/curve, group/ungroup, etc. to find if any variables cause this to happen or not.
    Also, with the new Hard Drive did you reinstall the OS and Applications or was this a separate drive from your startup dirve? Did you have to reinstall FreeHand and remember to add all the updates? also set the preferences to your last version?

  • Is save for web in JPEG format lossless when quality is 100%?

    I am trying to figure out if I can reduce optimised JPEG sizes further than what Photoshop can offer.
    My boss has recently questioned whether the file sizes can be reduced using lossless JPEG's further than the sace for web function in photoshop.
    From what I can make of it, lossy is the option on GIF files, and therefore I am assuming that the optimisation is lossless for a JPEG at 100 percent quality and lossy when the quality is reduced?
    I just want to clarify that I am saving images for the web at the smallest size I can without losing too much quality.
    All the images I save are 450px wide @ 75 dpi, but vary in length from 800px high to 1500px high, but have to be saved under 100kb.
    Can anyone clarify the lossless and lossy in JPEG format in save for web?
    Thanks
    Ray

    As c. says above, JPEG is a lossy compression - there is no lossless JPEG.
    PNG 24bit offers lossless compression, that is it performs compression analogous to a zip archive, whereas JPEG works by (in extremely lay terms) building a new image that resembles the original.
    GIF and PNG exports let you reduce the number of colours to get better compression - there are fewer pixel differences to compress at 8bit colour depth. Hence a 16 colour PNG will have a vastly smaller file size than a 24bit PNG, and depending on the image may be much smaller than a similar quality JPEG.
    Depending on how far off your 100KB ceiling you are, you may be able to improve your file exports by cleaning up the source image - reduce noise and if possible explore exporting as 8bit pngs with fewer colours - avoid using diffusion or noise in the export options. Find the balance between acceptable file size and image quality... photographs tend to be the hardest thing to compress because there's so much detail data, especially in darker (low light) areas.

  • Jpeg formatting problems(what am i missing?)

    Ok, so I have been importing photos into FCE with no problems with the exception of photos taken in the vertical. I figured out how to rotate, but when I do that the photo is blurry and it looks squeezed. How do I correct this? I am assuming it is simple, I am stumped at this point.
    I do not have any photo editing software, all photos are in jpeg format.
    Thanks....

    Tom,
    Thanks! I guess the photo wasn't rotated. It was simple...
    As far as the monitor, no monitor. I am looking into getting one, but for now I am just using the laptop and the small window in FCE. Any suggestions?
    I was working using preview before I imported the photo. It was viewed in the right aspect in preview, I guess it wasn't saved that way. I opened it up, re-saved it, imported it again and now all is working!
    Thanks a million!
    Respectfully,
    Jeff

  • How do I save my video in jpeg format so I can add picture to it and burn a DVD through Photo Explosion version 4

    How do I save my video in jpeg format so I can add picture to it and burn a DVD through Photo Explosion version 4

    LRP
    Thanks for the follow up.
    In Premiere Elements 13/13.1, your export choices are in the Publish+Share section of the project. There are several choices and sub-choices.
    Example: Publish+Share/Computer/and then a list of choices under that, such as, MPEG, AVI, AVCHD, XAVC-S, Windows Media, QuickTime, Image, Audio.
    And each has Presets which define the export settings. Adobe offers default settings which are usually optimized ones. But, it also allows you to customize the preset selected. You do that by clicking on the Advanced Button of the selected preset and customizing the settings under the Video Tab, Audio Tab, and, if applicable, Multiplexer Tab.
    From what you wrote, I thought that you might be asking about exporting a video with a video codec = Photo JPEG.
    To do that you would to to
    Publish+Share
    Computer
    QuickTime
    with Presets = either the one for 4:3 of 16:9 as appropriate for your project,
    and then clicking on the Advanced Button, and then the Video Tab under the Advanced Button.
    Then selecting Photo JPEG for the video codec field.
    Tip: The QuickTime choice is not seen unless you scroll down the list of Computer choices. Use the thin scroll bar to the right of the Computer choices.
    Please explore Premiere Elements 13/13.1's Publish+Share/Disc/DVD with standard or widescreen preset for your creation of the DVD-VIDEO on DVD disc.
    The Premiere Elements timeline destined for this choice could consistent of supported photos and or videos.
    Please consider.
    Any questions and need clarification, please do not hesitate to ask.
    ATR

  • I need help with boot camp. "Back up the disk and use Disk Utility to format it as a single Mac OS Extended (Journaled) volume. Restore your information to the disk and try using Boot Camp Assistant again."

    This message appears every time I try to partition my disk:
    "Back up the disk and use Disk Utility to format it as a single Mac OS Extended (Journaled) volume. Restore your information to the disk and try using Boot Camp Assistant again."
    I verified my Macintosh HD disk on Disk utility and then tried to repair it, but I am unable to click the repair button.
    It says it's not available because the startup disk is selected.
    I don't know what to do or how to go about both these problems.
    Please, any suggestions?

    This message appears every time I try to partition my disk:
    "Back up the disk and use Disk Utility to format it as a single Mac OS Extended (Journaled) volume. Restore your information to the disk and try using Boot Camp Assistant again."
    I verified my Macintosh HD disk on Disk utility and then tried to repair it, but I am unable to click the repair button.
    It says it's not available because the startup disk is selected.
    I don't know what to do or how to go about both these problems.
    Please, any suggestions?

  • Can someone please tell me how to format a new disk to ZFS format?

    I have a Sun v240 with Solaris 10 update 8 installed on a single 73GB harddisk. Everything is working fine. I just purchased a another identical harddisk online. I plugged the disk into my v240 and ran 'devfsadm' and solaris found the new disk. I want to add this disk to my existing ZFS pool as a mirror. However, this disk was originally formatted with a UFS file system. So when I run:
    zpool attach rpool c1t0d0 c1t1d0I get:
    /dev/dsk/c1t1d0s0 contains a ufs filesystem.I understand the error message but I don't know how to format the disk to have a ZFS file system instead. Note that I am extremely new to Solaris, ZFS, and pretty much everything Sun - I bought this server on eBay so that I could learn more about it. It's been pretty fun so far but need some help here and there.
    For some reason I can't find a single hit on Google telling me how to just simply format a disk to ZFS. Can I use the 'format' command? Maybe you don't "format" disks for ZFS? I have no idea. I might not have the right terminology. If so, apologies. Can anyone help me on this?
    Thanks a lot! =D
    Jonathon

    Yes, you were right. The partitions were totally different. Here is what I saw:
    For c1t0d0:
    # format
    Part      Tag    Flag     Cylinders         Size            Blocks
      0       root    wm       0 - 14086       68.35GB    (14087/0/0) 143349312
      1 unassigned    wm       0                0         (0/0/0)             0
      2     backup    wm       0 - 14086       68.35GB    (14087/0/0) 143349312
      3 unassigned    wm       0                0         (0/0/0)             0
      4 unassigned    wm       0                0         (0/0/0)             0
      5 unassigned    wm       0                0         (0/0/0)             0
      6 unassigned    wm       0                0         (0/0/0)             0
      7 unassigned    wm       0                0         (0/0/0)             0For c1t1d0:
    # format
    Part      Tag    Flag     Cylinders         Size            Blocks
      0       root    wm       0 - 12865       62.43GB    (12866/0/0) 130924416
      1       swap    wu   12866 - 14079        5.89GB    (1214/0/0)   12353664
      2     backup    wm       0 - 14086       68.35GB    (14087/0/0) 143349312
      3 unassigned    wm   14080 - 14086       34.78MB    (7/0/0)         71232
      4 unassigned    wm       0                0         (0/0/0)             0
      5 unassigned    wm       0                0         (0/0/0)             0
      6 unassigned    wm       0                0         (0/0/0)             0
      7 unassigned    wm       0                0         (0/0/0)             0So then I ran the following:
    # prtvtoc /dev/rdsk/c1t0d0s0 | fmthard -s - /dev/rdsk/c1t1d0s0
    fmthard:  New volume table of contents now in place.Then I rechecked the partition table for c1t1d0:
    # format
    Part      Tag    Flag     Cylinders         Size            Blocks
      0       root    wm       0 - 14086       68.35GB    (14087/0/0) 143349312
      1 unassigned    wu       0                0         (0/0/0)             0
      2     backup    wm       0 - 14086       68.35GB    (14087/0/0) 143349312
      3 unassigned    wu       0                0         (0/0/0)             0
      4 unassigned    wu       0                0         (0/0/0)             0
      5 unassigned    wu       0                0         (0/0/0)             0
      6 unassigned    wu       0                0         (0/0/0)             0
      7 unassigned    wu       0                0         (0/0/0)             0Woo-hoo!! It matches the first disk now! :)
    Then I tried to attach the new disk to the pool again:
    # zpool attach -f rpool c1t0d0s0 c1t1d0s0
    Please be sure to invoke installboot(1M) to make 'c1t1d0s0' bootable.
    Make sure to wait until resilver is done before rebooting.
    bash-3.00# zpool status
      pool: rpool
    state: ONLINE
    status: One or more devices is currently being resilvered.  The pool will
            continue to function, possibly in a degraded state.
    action: Wait for the resilver to complete.
    scrub: resilver in progress for 0h0m, 0.40% done, 0h58m to go
    config:
            NAME          STATE     READ WRITE CKSUM
            rpool         ONLINE       0     0     0
              mirror-0    ONLINE       0     0     0
                c1t0d0s0  ONLINE       0     0     0
                c1t1d0s0  ONLINE       0     0     0  30.3M resilvered
    errors: No known data errorsBoo-yah!!! ++Does little dance++
    Then, after resilvering completed I ran:
    # installboot -F zfs /usr/platform/`uname -i`/lib/fs/zfs/bootblk /dev/rdsk/c1t1d0s0I think I'm starting to understand this now. I also shutdown the server to the OpenBoot prompt and booted off of the new disk and it worked! Also, my bootup time to login has drastically decreased - I would say it's about half the time it was before I added the mirror disk. So I believe the server is properly reading from both disks simultaneously in order to get better bandwidth. Cool! :)
    Thanks for the help!
    Jonathon

  • Unable to save PDF's from Internet Explorer. Error "The document could not be saved. The disk you were saving to or the disk used for temporary files is full. Free some space on this disk and try again, or save to a different disk."

    We are currently in a published desktop environment in Citrix XenApp 6.5.  Server is running on Windows 2008 R2.  Users are not able to save PDF's into the redirected folders (ie Desktop or My Documents).  Exactly same issue described in "The disk you were saving to or the disk used for temporary file is full...."  Anyone has any suggestion??

    Same problem here. Any ideas?
    Saving with Shortcut "CRTL+SHIFT+S" works just fine.
    Using IE 11.0.9600.17728 and Adobe Reader 11.0.10

  • Hello, I have a series of language cd's that I am trying to put onto my iTunes but when I download them, they will not save separately instead they are saving as the first disk so i am ending up with 3 disks on 1. Please help

    Hello, I am trying to copy a series of language cd's onto iTunes but each cd will not save separately, instead it is saving all as one disk. So I am ending up with 3 disks on 1 with 3 different track1, 2 etc. Please help as I am sure there is an easy solution to this that I have no clue about. Thanks

    After you insert the CD but before you import it into iTunes, select all tracks and set the disc number to 1, 2, 3 ... as appropriate.

  • Boot Camp error: The startup disk cannot be partitioned or restored to a single partition. The startup disk must be formatted as a single Mac OS Extended (Jounraled) volume or already partitioned by Boot Camp Assistant for installing Windows.

    Hi!
    I am getting the error:
    "The startup disk cannot be partitioned or restored to a single partition.  The startup disk must be formatted as a single Mac OS Extended (Jounraled) volume or already partitioned by Boot Camp Assistant for installing Windows."
    I read up some on google, but all of them says that they have crated a partition and that is the problem, I only have the standard "Macintosh HD".
    I tried to create a partition manually in disk utility but then the error message: "Partition failed with error message: Could not unmount disk."
    Can anyone help me? It's driving me crazy.
    Thanks.

    This message, and threads like yours got asked daily for over two years, now it is only a couple times a week!!
    Is it so hard to follow through? you were to have backup already, clones are best, then erase/format and restore.
    Then partition.
    Some have been able to use Disk Utility booted from OS X DVD or another drive, and repair the drive.
    You have to use Boot Camp Assistant (99.9% anyway) to create and achieve a proper Windows Master Boot Record partition.

Maybe you are looking for

  • 805a01f4 error with updating nokia drive

    Hello, I have bought a new windows 8 phone from Nokia. Every feature which is default with the phone is great and I have no issues with any of them. But when am trying to open the Windows Store to update Nokia drive, am getting the error code with th

  • Creating scrolling text on an iWeb page

    I came across Old Toad's Test site and was suitably impressed by the enhancements detailed on his home page. (I did not post the link as I did not want to breach any confidentiality). Q) How do I get scrolling text on an iweb page? By way of an exper

  • Lookups and BC4J

    How can I get BC4J to handle my look ups without including the key value in the form? I'd like to be able to just show the value, without the key value, but, of course, have the key value be inserted into the main table. Anyone doing this? Joe

  • IPod Artwork Copy to iPod Proceedure

    Anyone else find that if they update the artwork of an album or video, and sync up your iPod, that the whole file needs to be transfered again, not just updated with the new artwork. It kind of ***** if you have a 500mb movie and all you do is update

  • Installing JavaBean in the JDev10g Component Pallet

    I'm a newbie to Java as well as to JDeveloper, so this is hopefully something very simple. I'm trying to create a new JavaBean and install it to the component pallet on it's own page. I've gone through the steps in the help, and I have my new page, a