How do I control the quality of JPEG images?

I've written a program that scales a set of JPEG images down to various dimensions. I'm happy with the speed of execution, but quality of the images could be better. How do I specify the quality of the JPEG images I create? In graphics editors, I'm given the option of controlling the lossy-ness (?) of JPEGs when I save them, either reducing image qualify to shrink the file size or vice versa. How can I do this programmatically?
Thanks

Hi Jhm,
leaving aside the scaling algorithm, to save an arbitrary image with 100% quality you'd use
something like the following code snipet below
regards,
Owen
// Imports
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
public boolean saveJPEG ( Image yourImage, String filename )
    boolean saved = false;
    BufferedImage bi = new BufferedImage ( yourImage.getWidth(null),
                                           yourImage.getHeight(null),
                                           BufferedImage.TYPE_INT_RGB );
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage ( yourImage, null, null );
    FileOutputStream out = null;
    try
        out = new FileOutputStream ( filename );
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder ( out );
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam ( bi );
        param.setQuality ( 1.0f, false );   // 100% high quality setting, no compression
        encoder.setJPEGEncodeParam ( param );
        encoder.encode ( bi );
        out.close();
        saved = true;
    catch ( Exception ex )
        System.out.println ("Error saving JPEG : " + ex.getMessage() );
    return ( saved );
}

Similar Messages

  • How can I improve the quality of resized images ?

    Hello,
    I've written a program for batch resizing Jpegs which is working fairly funky however the quality of the resized images could be a bit better. Is there any way of doing a smoother resize of the images ? I'm currently using:
    AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scaleX, scaleY), null);
    theImage = op.filter(theImage, null);
    Also I'm having trouble with some Jpegs taken with my friends digital camera. When I resize the vertical (480*640) ones the colours get all messed up while the horizontal (640*480) ones turn out fine. This only happens with Jpegs from his camera ! The colour scrambling looks very similar to what I was getting with all Jpegs when I used the below code to resize images:
    AffineTransform scaler = new AffineTransform();
    scaler.scale(scaleX, scaleY);
    AffineTransformOp scalerOp = new AffineTransformOp(scaler, AffineTransformOp.TYPE_BILINEAR);
    theImage = scalerOp.filter(theImage, null);

    See bug: 4712797

  • How do I download the full resolution JPEG images from my iPhone to my flash drive through my mac?

    When I plug my iPhone 5S into my MacBook Pro through a USB 2.0 to Lightning cable, the phone doesn't show up as a device in finder (#imisssnowleopard). How can I grab the images off the phone and put the files on my flash drive? (without using the iPhoto library compression or the iTunes photo compressing) (iPhone 5S with latest iOS)(15" MacBook Pro June 2009, most recent OS X)

    Use Image Capture to import the pictures wherever you want to have them.
    ~Lyssa

  • Improve quality of JPEG images

    Hi
    I have an application which saves images in JPEG format after editing (well, many applications does that, but this is only a fraction of what this application does) :-)
    I can't use any other formats due to size restrictions. The problem is Image Editing module of this application has operations like line drawing and text inserting. When I save the image, fine lines (especially texts) are getting blurred.
    Is there any way I can increase the quality of JPEG files saved? I understand that JPEG is not meant for sharp lines and texts but with Photoshop, even fine lines and texts appear good when saved as a high quality JPEG file. Is there any such method in Java by which I can increase the quality of JPEG images?
    Thanks in advance...

    Is there any way I can increase the quality of JPEG files saved? I understand that JPEG is not meant for sharp lines and texts but with Photoshop, even fine lines and texts appear good when saved as a high quality JPEG file. Is there any such method in Java by which I can increase the quality of JPEG images?I JPEG is a non-conservative compression format (you do not get back exactly what you put in, it has "acceptable degredaton"--I talked with the author before it became popular and he explained what JPEG was all about--high compresses resulting in a small size for internet communications over dialup.
    In more recent times I've seen quality factors brought into play with JPEG, but as you have stated, even in Adobe Photoshop under the highest quality, you still have degradation. I've seen some hint and some state that you can get a lossless JPEG, but I've not encountered it yet.
    In any case, if you do find a "lossless JPEG" the size of that file is going to be bigger than you are looking at now. You may consider other file formats--TIFF or there are even more recent files formats that have higher conservative compression algorithms.

  • How can I keep the quality of an MP4 video high when I export an interactive PDF from InDesign?

    I am making an Interactive PDF with embedded MP4 video using InDesign.  When I view the video in the PDF it has degraded the quality and the colour contrast is poorly affected.  I can have the video as a floating window but this gives a harsh black line around the video when it plays which is not acceptable.
    Can anyone advise how to maintain the quality of the original video when it is embedded?

    You can control the quality of the video (aspect ratio, pixel dimensions, frames/minute, etc.) by using the Adobe Media Encoder which comes with InDesign CS5 or later installations, including InDesign CC. InDesign only includes what you have placed and passes it on to the PDF file. There are no video quality controls in InDesign.
    You cannot change the way Adobe Acrobat or Adobe Reader displays the MP4. If you don't like the way Acrobat/Reader handles display of a floating window, then you'll have to display it within the page. For more info, inquire in the Rich Media Acrobat forum.

  • Is there a way to control the quality of my pdf file when exporting from a .pse file?

    Is there a way to control the quality of my pdf file when exporting from a .pse file?
    Hi,
    I have 2 pages in all in a .PSE file.
    When I try to export it as .PDF, the quality is very poor. I cannot change it to a better quality.
    Please advise how I can export the file so that i can have better quality.

    Rik Ramsay wrote:
    To expand a little on what Jongware said, normally choosing vector over bitmap will decrease the filesize. If the vector art is very complex though, this will not be true.
    Yup, a logo as bitmap takes up more space than the same as a vector -- unless the vector image is bitmap heavy (think Drop Shadow, Outline Glow; these are actually bitmap effects).
    Also, check your PDF version. "Older" versions do not support live transparency, the latest do. Then again, you cannot use live transparency if you suspect your viewers may be using Mac OS X, because Apple's own PDF viewer sucks big time.

  • How can I control the image size when I export form iphoto, the choice is too limited, I need to send a photo under 3 MB but if I choose high quaulity it is only 1.1 and i need to keep the best quaulity I can. Thanks for help.

    How can I control the image size when I export form iphoto, the choice is too limited, I need to send a photo under 3 MB but if I choose high quaulity it is only 1.1 and i need to keep the best quaulity I can. Thanks for help.

    Any image can only be as large as the Original. With a program like Photoshop you can UpRes an image and get it to a bigger size, larger files size as well, but the actual quality of the image will be degraded, depending on the UpRes system and the original quality of the image.
    iPhoto is not the program to be doing that in and I don't think it even has that option.
    So I suspect the image you are trying to send isn't much bigger than what you are getting. You can also try Exporting it from iPhoto to yopur desktop and see what size you end up with. If it is still that 209KB +/- file size then that is the size of the original image.

  • How can I control the zoom on my mac mouse?

    How can I control the zoom function on my mouse? In the middle of working on things my hand will rub the mouse by accident and all of a sudden the context within the screen is large. I have no idea of how to work this feature on my mouse and most times to get it to return to normal, I have to escape out of the work I am performing.

    If you are pressing the "Control" button on the Mac keyboard, scrolling up will zoom in and scrolling down will zoom out. You can disable this if it annoys you through System Preferences > Universal Access. If you are using Mountain Lion, it would be System Preferences > Accessibility.
    Uncheck the in the "Seeing" or "Zoom" section that says "Use scroll gesture with modifier keys to zoom".  It may be slightly different if you have an older OS X version. I have Mountain Lion and am going off of memory on the older versions.

  • I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    In landscape mode, the mailbox list is automatically displayed (in portrait mode, you will need to tap the button to,show it).
    To edit the list, tap edit as shown below.

  • How can I control the window size of my output?

    Hi,
    I'm drawing a blank... How do I control the size of the window that my project is viewed in? Right now, it's the entire browser window.
    Thanks,
    Janice

    Hi,
    From your post, I assume you are creating WebHelp output.
    You  need to create a window for the help in the Project Set-up pod. Then,  you need to make sure you call the output so that the window is used.  See http://www.grainge.org/pages/authoring/calling_webhelp/calling_webhelp.htm.  This article on Peter's site give you an overview over the  possibilities of calling context sensitivive webhelp and also tells you  how to specify the needed window. Also, the installation directory of  RoboHelp 8 contains a directory called CSH API. In there are example  API's your developer can use to call the help.
    Greet,
    Willam

  • How do I control the order of all day events in iCal?

    How do I control the order of all day events in iCal?  Even if I painstakingly try to
    re-order the events the way I want them, when they print, they are in a different order.
    I have searched other forums and no one seems to have an answer to this.  Has
    anyone found the solution?  Thanks!

    I also have this issue, where the events in iCal change when viewing in print preview or printing. I even notice they will switch if I try to print again??!!! I am using different calendars to show different colours. and they are setup on iCloud not on my mac.
    it is becomign frustrating when I print 2 months worth and ssome events are correct in order and alas some will change when I print again!
    Can anyone help please?
    thanks

  • How can I control the volume in a Appletv movie from my remote control App. In my IPad ?.

    How can I control the volume in a Apple Tv movie from my remote control App. In my IPad ?.

    There is not now, nor has there ever been a version of flash for any iOS device.
    Adobe has abandoned mobile flash, so there never will be.
    Browsers like iswifter or photon may work for you, but don't hold your breath.
    Check app store for an app of whatever game you want.

  • How can I control the size of a cell in the GridBagLayout?

    Hi,Swing Gurus
    I am developing a swing-based program using JBulider5 enterprise.
    It seems to me that the GridBagLayout is really a hard nut!
    How can I control the size of a cell in the GridBagLayout?
    It seems that I cann't control the size of a cell directly.
    But how the size of a particular cell is determined when I switch the layout manager from XYLayout to GridBagLayout?
    Thx in advance!
    Regards,
    Justine

    hi,i have not done what you are asking but there are fields like
    COLUMNWIDTH, MINSIZE, MAXGRIDSIZE, PREFEREDSIZE to which you can set the appropriate values and test for your need.hope this helped.bye martian.

  • How do i change the quality settings of my printer? the options are there but greyed out!

    how do i change the quality settings of my printer? the options are there but greyed out! ie on my old HP I could print in draft if i wanted to print a doc to read and then bin...the option/box is there but greyed out so I can't select. HELP!!!

    You can change the background display color in the playback preferences, either black, white, or checkerboard. This does not change the output color. If you want to add a color to the video, you have to place a custom generator underneath your video and change the color in the inspector.

  • How can I control the order of playback on MuVu Mix (USB 2.

    What determines the order of playback of music files stored on the MuVu Mix (USB 2.0)? How can I control the order?
    Apparently it is not name order. The music titles are prefixed by sequential numbers. But that is not the order that the files play back.
    I tried erasing all contents, then copying the files one by one to the MuVo Mix in the order that I want them to play back (name order). But that is not the order that the files play back.
    By the way, in both case, I removed the ".dat" file first. (I also tried keeping the ".dat" file, to no avail.)

    SSR wrote:
    > on the newer MuVos (which I would have thought included the Mix)
    > it's filename order. Other than that it's hard to know, but it sounds
    > like you ought to contact Support to check.
    I did, and they confirmed (very quickly; kudos!) what you and I both expect: the play order is determined by the alphabetical order of the file names. The mistake was mine. I ass-u-me-d that the MSWin folder "Name ^" order was correct. I did not realize that it is not exactly alphabetical when the file name begins with a number (e.g, the track number). I had renumbered songs from a second CD by simply adding 00 to the track number. Thus, songs and 2 of the first CD are played after songs 08 and 09 of the second CD, as they should alphabetically, even though they appear in the order , 2, 08, 09 in the "Name ^" list. Klunk! Mea cupla!

Maybe you are looking for

  • Error Message NSURLErrorDomain error -1012.

    I get this error message when I try to update.  I had just downloaded Safari Version 7.0.4 update 2 days earlier.  What can I do to resolve the issue?

  • Fireworks CS4 toolbars not loading properly

    Hi Downloaded Fireworks CS4, and after installing it noticed that some of the toolbars are "missing". Well, not actually missing, but just transparent....I can see my desktop background through the workspace. Is this a driver compatibility issue, or

  • REP-0736 error

    Hi all, Am in the middle of an upgrade program, taking Reports 2.5 to 9. Some of our reports are returning the following error: REP-0736: There exist uncompiled program unit(s) I have looked through a lot of information (metalink and here) and have f

  • Yosemite and USB Headphones

    Dear all, please advise. In ordinary situation when incoming call on iPhone 5s 8.0.1 redirected to Facetime on MBP 13" retina 2014 I start speaking to internal MBP microphone and hearing sound from internal speakers. I`ts fine. But if any WIRELESS he

  • How does the system override PR00 when PR01 is entered.

    I just need to understand how PR01 overrides PR00 when entered in pricing.