How to create a lossy JPEG 2000 picture?

Hi there.
Now I am working on an app. to compare the quality between a traditional JPEG and the new JPEG2000 format.
Although I did not find the ways to encord JPEG2000 format in basic JAI, another API jai_imageio-1_0_01 does provide the way to do it.
The default parameter in the J2KImageWriteParam is for a lossless encord, the result is perfect, of course. But more importantly, I want to try the lossy ones so that I can reduce the outstream size.
The problem is here, when I just change the encoderate throught the setEncordingRate method, the result is terrible, which I am sure is a failure. I do not know why. There are many parameters I can set, does it mean I should change several at the same time, not just the encodingrate? And if I change the writeparam should I change the readparam too to decord?
My sample code is following, in it, I cpatured the screen as the source and write it into .jp2, then read it out to show.
Please help me, thanks a lot.
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import javax.media.jai.JAI;
import com.sun.media.imageio.plugins.jpeg2000.*;
import javax.imageio.stream.*;
import javax.imageio.ImageIO;
import com.sun.media.imageio.plugins.jpeg2000.J2KImageWriteParam;
import javax.imageio.*;
import javax.media.jai.operator.AWTImageDescriptor;
import javax.media.jai.RenderedOp;
class screen18 extends Frame{
     BufferedImage sh=null;//for Captured screen
     Rectangle screenSize;
     BufferedImage bi= new BufferedImage(1024, 768, BufferedImage.TYPE_INT_ARGB);           
     public screen18()
          addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e){
          System.exit(0);
          screenSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
          sh= new BufferedImage(1024, 768, BufferedImage.TYPE_INT_ARGB);      
          //Capture the screen
          try{
               sh = (new Robot()).createScreenCapture(screenSize);
          }catch(Exception ex) {System.out.println(ex);}
     ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName("jpeg 2000").next();
     ImageOutputStream ios = null;
     try {
          OutputStream os1 = new FileOutputStream("j2000.jp2");
          ios = ImageIO.createImageOutputStream(os1);
          writer.setOutput(ios);
          J2KImageWriteParam paramJ2K = new J2KImageWriteParam();
          //You can set whether it is lossy here
          //paramJ2K.setLossless(false);
          //paramJ2K.setFilter("w9x7");
          //paramJ2K.setEncodingRate(Double.MAX_VALUE*0.9);//key point
          System.out.println("JPEG2000 Parameter: ");
          System.out.println("getCodeBlockSize: "+paramJ2K.getCodeBlockSize());
          System.out.println("getComponentTransformation: "+paramJ2K.getComponentTransformation());
          System.out.println("getEPH: "+paramJ2K.getEPH());                               
          System.out.println("getLossless: "+paramJ2K.getLossless());
          System.out.println("getEncodingRate: "+paramJ2K.getEncodingRate());
          System.out.println("getFilter: "+paramJ2K.getFilter());           
          System.out.println("getProgressionType: "+paramJ2K.getProgressionType());           
          System.out.println("getSOP: "+paramJ2K.getSOP());
          System.out.println("getWriteCodeStreamOnly: "+paramJ2K.getWriteCodeStreamOnly());                     
          RenderedOp renImage7=AWTImageDescriptor.create(sh,null);
          IIOImage ioimage = new IIOImage(renImage7, null, null);
          writer.write(null, ioimage, paramJ2K);
          ios.flush();
          writer.dispose();     
     }catch (IOException ex) {System.out.println("Mistake is here when produce a J2K");}
          ImageReader reader1 = (ImageReader)ImageIO.getImageReadersByFormatName("jpeg 2000").next();
     try {                                              
          ImageInputStream iis = ImageIO.createImageInputStream(new File("j2000.jp2"));
          reader1.setInput(iis,false,true);
          J2KImageReadParam paramJ2K1 = new J2KImageReadParam();
          System.out.println(paramJ2K1.getDecodingRate());
          paramJ2K1.setDecodingRate(Double.MAX_VALUE*0.9);
               bi = reader1.read(0, paramJ2K1);
          reader1.dispose();
     }catch (Exception ex) {System.out.println("Mistake is here when extract a J2K");}     
     public void paint(Graphics g)
          g.drawImage(bi,0,0,this);
     public static void main(String args[])
          screen18 s = new screen18();
          s.setSize(1024,768);
          s.show();
}

Hi Wayne,
if you take a JPEG image from your file system as a source instead of the Robot, the lossy encoding works:
sh = ImageIO.read((new File("C:\\Images\\Bild0.jpg")));instead of
sh = (new Robot()).createScreenCapture(screenSize);and later...
paramJ2K.setLossless(false);
paramJ2K.setFilter("w9x7");
paramJ2K.setEncodingRate(Double.MAX_VALUE * 0.5);//key pointBest regards
Dominic

Similar Messages

  • How to create an interactive jpeg for use in an email?

    Hello everyone,
    I'm thinking that this must be possible but am not quite sure even where to start. Here's what i want to do..
    Include an interactive image (I'm guessing jpeg) with clickable buttons for inclusion in an email.
    When each button is clicked on, these would fill in a linked spreadsheet.
    So my first question, is this possible with Adobe software? I have CC so access to a lot more programmes than what i currently use! And if this is possible, would somebody be ever so kind as to tell me how or even where to start?
    Thanks in advance!
    Katie.

    This has nothing to do with PS. Pictures cannot be "interactive". You are talking about creating a HTML e-mail blast and that requires Muse, Dreamweaver etc.. And forget about filling spreadsheets. That's another discipline and requires extensive scripting or a dynamic server backend. Sorry, but to be candid: Since you haven't even figured out the basics, you are way in over your head. Time to read some primers on HTML and all that...
    Mylenium

  • HT4168 How to create an ePub book with pictures next to text

    Before you say it cannot be done, that pictures have to be inline with the text please be knowledgeable on the example first.
    Apple puts out "iPad @ work" in an epub format that does just that.
    It has a logo on the top right of the page and appears to have ibook page selection below the page. This is not the typical ePub format, nor is it the typical iBook format. It is getting very frustrating to have people say it can not be done and not offer a solution as to how this book put out by apple, identified as an ePub book has this format.

    Hi Richard,
    In this community, "It cannot be done" means "It cannot be done with Pages '09."
    The document in question was, obviously, produced using an application oter than Pages.
    Regards,
    Barry

  • How to create a video out of pictures?

    I remember it being dead easy but I just cant find a way to
    do it now.
    Basically I wanna create an AVI file out of my photos, with
    some music, maybe with a fade away effect.
    THANK YOU FOR YOUR HELP!!

    You can import all the fotos to your timeline add your music
    and the fades, then move over to File -> Export Movie
    -> and choose as filetype .avi

  • JPEG 2000  & Camera Raw?

    I converted a nef  and a regualr jpeg to a Jpeg 2000 picture and used the various save options as a test.  In all cases I can not open it in camera raw, that option is grayed out.  Is this by design?
    I notice in Bridge Camera Raw Preferences  there are only options for jpeg and tiff images to be opened in camera raw.  Is this an oversight?
    Also, using Bridge one can not add keywords as the message appears "xxxxx.jpf can not store XMP metadata".
    In Windows Explorer the add tags box does not appear as an option either, so it can't be blamed on Bridge.
    Has any one else experienced these problems with j2000 images?  Is jpeg 2000 ahead of the curve, or just a flash in the pan?

    I understand that a flattened image composite is stored when PSD compatibility is set, but I didn't know it was a JPEG (or that there's a JPEG preview in a PSD file at all, save for maybe a thumbnail).
    Can you clarify that?  Is this JPEG preview you speak of the flattened composite, or are we talking about yet a different preview?
    And do we lose more than just layers, but also color depth when we re-open a PSD through Camera Raw?
    -Noel

  • How to create a pdf file with CS5

    Hello, I'm new to PhotoShop CS5 and haven't figured out yet (despite two hours of trying) how to create a pdf file with pictures and texts.  Can someone please help me with this ?  The "help" button in CS5 doesn't seem to cover this question.  Nor do the FAQs.
    Thank you very much.

    Save As... Photoshop PDF.

  • How to create a browser to view JPEG files?

    Hi people,
    just wondering if anyone knows how to create a simple browser to view JPEG or some other image files?...Is there e.g. or tutorial provided by Sun on this...
    AG

    Sure, the Java Tutorial duscusses working with ImageIcons in an applet (or application) here:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
    The IconDemoApplet example is just such an image browser. Cheers,
    Chris

  • How to create a Picture/Image field in a PDF form ?

    Hi,
    I'm creating a PDF form including several fields (Text box, Checkbox, radiobuttons,...). My users will enter there personal data in the PDF form and send it back to me (or print it).
    I would like to create a special field for picture of the user: The user should be able to select a JPG document on his local computer and drag/copy the picture in this picture-field. The objective is to have the picture of the user in the form he will send (as PDF) or print.
    How can I create a field ("Please add your picture here") to allow people with Reader to add a picture in the PDF form ?
    Best regards

    This is possible with a form created by LiveCycle Designer. For further questions use the forum for LiveCycle Designer.

  • How to create 2 or 3 links URL in a jpeg ?

    How to create 2 or 3 links URL in a jpeg ?
    Do i use photoshop ?
    Thank you

    Images cannot contain links. All that stuff is done in the web page source code, e.g. using image maps, interactive SVGs or JavaScripts that track coordinates and respond accordingly. You will have to use a web authoring tool like Muse or Dreamweaver to produce such stuff, but since you seem to be a complete beginner, I strongly urge you to read up at least on some basic stuff about HTML, CSS and how the web ticks in general or you'll be forever lost.
    Mylenium

  • How do I create motion for still photos/pictures. I'd like to pan/scan & zoom. Please help!

    How do I create motion for still photos/pictures. I'd like to pan/scan & zoom. Please help!

    You kind of answered your own question..
    Check out Motion in the FX Control Window and learn how keyframing works..

  • I'm debutante in oracle 10g how to create a database with picture?

    I'm debutante in oracle 10g how to create a database with picture? help please

    d7401ec1-d4d6-4e54-9eb4-2181ac367d0c wrote:
    I'm debutante in oracle 10g how to create a database with picture? help please
    Oracle 10g is obsolete.  Oracle 11g is already at terminal release.
    Have you installed the Oracle rdbms software?
    Installing Oracle and Building the Database
    If you are going to be a professional DBA, you need to learn to
    1) read the documentation
    2) wean yourself from dependence on pictures and GUIs.
    3) read the documentation
    =================================================
    Learning how to look things up in the documentation is time well spent investing in your career.  To that end, you should drop everything else you are doing and do the following:
    Go to  docs.oracle.com.
    Locate the link for your Oracle product and version, and click on it.
    You are now at the entire documentation set for your selected Oracle product and version.
    BOOKMARK THAT LOCATION
    Spend a few minutes just getting familiar with what is available here. Take special note of the "books" and "search" tabs. Under the "books" tab (for 10.x) or the "Master Book List" link (for 11.x) you will find the complete documentation library.
    Spend a few minutes just getting familiar with what kind of documentation is available there by simply browsing the titles under the "Books" tab.
    Open the Reference Manual and spend a few minutes looking through the table of contents to get familiar with what kind of information is available there.
    Do the same with the SQL Reference Manual.
    Do the same with the Utilities manual.
    You don't have to read the above in depth.  They are reference manuals.  Just get familiar with what is there to be referenced. Ninety percent of the questions asked on this forum can be answered in less than 5 minutes by simply searching one of the above manuals.
    Then set yourself a plan to dig deeper.
    - *Read a chapter a day from the Concepts Manual*.
    - Take a look in your alert log.  One of the first things listed at startup is the initialization parms with non-default values. Read up on each one of them (listed in your alert log) in the Reference Manual.
    - Take a look at your listener.ora, tnsnames.ora, and sqlnet.ora files. Go to the Network Administrators manual and read up on everything you see in those files.
    - *When you have finished reading the Concepts Manual, do it again*.
    Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime.
    =================================

  • How to create crystal reports using MSDE 2000?

    Post Author: S_Muhilan
    CA Forum: Deployment
    Hi,
    I am using Crystal report 8.5. My Database sqlserver 2000. I generated reports and are working fine.
    Now I want to use MSDE 2000 instead of Sqlserver 2000 due to license factor.
    My application is developed in VB 6. The all the parts of the application is working fine except the report.
    All reports produced Database DLL error.
    So I opened the report and try to verify the database. But it gives pdssql.dll not found. Database error.
    After this error, I tried to create a new report and found that there is no option for MSDE 2000 database selection under more database.
    I usually select Sql server 2000 database under More Database option of location wizard.
    How to create crystal reports using MSDE 2000?
    Is it due to crystal report 8.5 verison problem? I also have crystal report 11 licensed copy.
    Please give me the good solution as early as possible
    RegardsS. Muhilan

    To use the inproc RAS SDK with CR.NET, you'd have to purchase either (1) Crystal Reports XI Release 2 Developer edition, and apply Service Pack 2 or above, or (2) Crystal Reports 2008 (not Crystal Reports Basic that comes with Visual Studio 2008).
    Sincerely,
    Ted Ueda

  • I have taken over 9999 pictures with my phone and it is now creating duplicate names for the pictures starting back at 0001 making it difficult to manually upload my photos like i always have. How do i fix this?

    I have taken over 9999 pictures with my phone and it is now creating duplicate names for the pictures starting back at 0001 making it difficult to manually upload my photos like i always have. How do i fix this?
    (I tried to just write this as a reply to someone who had already asked the question whos problem was magically solved after posting the question and the site was not allowing me to post to it so here I am)

    Additionally, when I try to sort the photos by date to easily extract the newest photos which I have not yet uploaded, it is unable to put them in correct order regardless of the fact that the date is correct. Only the videos end up in chronological order for some reason while the photos stay in order by name.

  • I have over 2000 pictures in IPhoto how do I transfer to ICloud?

    I have over 2000 pictures in IPhoto how do I transfer to ICloud?

    You can't. iCloud is not a general purpose photo storage solution. The Photostream feature is only a conduit for transferring photos from iOS devices to other iOS devices and your computer. It only stores up to the latest 1000 photos for a maximum of 30 days.
    As Winston points out, you also cannot use iCloud on your current OS X 10.6.8 system, you'll need to upgrade to OS X 10.7.2 or later.

  • Hi - Re Keynote  I'm trying to figure out how to create a music album on USB flash drive. What I want is a background picture with 'click-buttons' to play each track listed, also similar for embedded videos and photos etc.  Is this possible with Keynote ?

    Hi - Re Keynote  I'm trying to figure out how to create a music album (as an artist) on USB flash drive, (accessible by both Mac and PC). What I want is a background picture with 'click-buttons' to play each track listed, and play in order (like a cd) - also similar for embedded videos and photos etc. This should all be on the one page.  
    Is this possible with Keynote, or any other software package for Mac (am using Macbook Pro) ?
    Gav 88

    Hi there,
    Yikes, it sounds like you've been doing a lot of work on this project... Unfortunately, however, this isn't the Adobe Encore forum, but the Acrobat.com forum. While it seems like an exciting question, we're not able to address issues pertaining to other Adobe products and services. Here's a link to the Adobe Encore forum, where you're more likely to get help for this specific issue:
    http://forums.adobe.com/community/encore
    Sorry not to be of more specific help to you. Best of luck!
    Kind regards,
    Rebecca

Maybe you are looking for

  • How to print list of calendar events?

    Hi, I'm trying to print a list of events for a specific calendar that only lists scheduled events, not days with nothing scheduled. After a time consuming process of delselecting all calendars I DON'T want on the list, selecting the time frame (4 mon

  • Prey game not launching after Security Update 2007-004

    After applying Apple Security Update 2007-004, Prey (Mac version) is not launching and continuously crashes on my computer. I have uninstalled all game files and reinstalled the game from the original DVD but with no success. Repairing disc permissio

  • Lightroom 1.2 flipped images horizontally

    I've noticed since my update that several Folders have the images flipped Horizontally. Anybody else have this problem? Any ideas for a fix other than manually selecting images in bunches and flipping back. PITA.. On a Intel iMac.

  • Clean install... should i have all these frameworks and plug ins

    from system profiler. it seems weird many aren't found in help. just curious if these are standard load with a complete erase and clean install? thanx for the help in advance Frameworks: Accelerate: Version: 1.4.2 Last Modified: 3/5/09 4:56 PM Get In

  • VMware Edition Faulty downloads crc errors

    Hello - I have been trying for days to download the software at this site> http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/102c6e47-cd8e-2a10-8b96-a2102923212f Download SAP NetWeaver 7.0 - Java and ABAP Trial Version on Linux -