Converting JPEG to BufferedImage using previously allocated BufferedImage

I have an application containing 11 Thumbnails fed by streams of JPEG images at 5 fps and a large panel that shows the image full size. Each thumbnail and the large panel are separate applets in a web page. The jpeg images are received directly into a byte array (byte[]) which is wrapped with a byte buffer. The images are then displayed using a jpeg reader which produces a new BufferedImage which is drawn using the awt graphics object drawImage method.
The application works great except that the image io library always allocates a new BufferedImage for each conversion. This creates a huge swing in memory use and on some "busier" or less powerful clients, the mark and sweep garbage collection sometimes does not get run often enough to prevent memory use from getting rather huge, even if I call System.gc() on a regular basis. The overall effect is that the amount of JVM memory goes through some pretty big swings and after enough of these swings, the application starts to bog down. Note that there is no actual leak: the swings return to a memory allocation level that does not grow with time, and it always hits this level after the mark and sweep.
To try to get this under control, I'd like to see if I can get a jpeg decoder that will write to an existing buffered image and its corresponding raster to avoid allocating a brand new RGB image for each frame. Is there any way to construct an image decoder for jpeg to awt renderable images that knows how to recycle existing BufferedImage/Raster objects?????
Thanks,
Paul

1. Get an image reader using ImageIO.getImageReadersByFormatName.
2. Use ImageReadParam and specify your existing BufferedImage as destination using readAsRenderedImage.

Similar Messages

  • How to convert jpeg to bmp using java code

    I want to convert a jpeg image to bmp image using java so that any coloured image can be converted to black&white using java. Is there any utility to accomplish this?
    Thanks in advance

    Try out this category on Esus:
    http://www.esus.com/javaindex/j2se/jdk1.2/javaawt/awtgraphics/2dgraphics/images/javaimagetypes/javaimagetypes.html
    Cheers,
    Joris

  • How to convert JPEG - PNG images using java?

    Hi,
    Has anyone done this before?
    Can you provide me with a sample code or point me to the direction on how this can be done?
    Are there any existing Java technology that supports this?
    Most grateful. Thanks.

    It's should be easy using Java Advanced Imaging (JAI). Try this.
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class convert {
      static public void main(String[] args) {
        String inName = args[0];
        String outName = args[1];
        RenderedOp source = JAI.create("fileload", inName);
        JAI.create("filestore", source, outName, "PNG", null);
        System.exit(0);
    }

  • How to convert JPEG Files into Streams for Darwin Streaming Server?

    Hi!
    Is there any possibility to convert JPEG Files locatet in a Folder into a Videostream for the Darwin Streaming Server, like Quicktime Broadcaster does with my iSight Video??? I know I can convert JPEGs into Movies using QuickTime Pro, but that is not exactly what I am seraching for: I have a folder, where some kind of Webcam writes about 5 JPEG pictures per second. Now I would like to have these pictures in converted into a videostream in realtime. QuickTime Broadcaster would be the weapon of choice if it would accept JPEG Files as input...
    Is there any posibility to solve this problem??
    CU Jan

    Hello Karthik,
    I just tried to solve my problem with your suggestions, unfortunately, my JSP channel still doesn't work :(
    The portal server keeps reporting "Server Error..." when I tried to add query at the end of the href.
    Do you still have any other suggestions?
    Thank you

  • 10.2 crashes when I try to convert old libraries for use in the new software. Is there a workaround for this? Or will i have to continue using the previous version to complete older projects?

    Final Cut Pro X 10.2 crashes when I try to convert old libraries for use in the new software. Is there a workaround for this? Or will I have to continue using the previous version to complete older projects? the only foreseeable solution is to begin any new projects on 10.2 or importing footage on 10.2 and starting form scratch--which is something i definitely don't want to do or have time to do. ANY advice, thoughts, or opinions would be greatly appreciated! Thank you!
    Running 10.10.3 // MacBook Pro (Retina, 15-inch, Early 2013) // 2.4 GHz Intel Core i7 // 8 GB 1600 MHz DDR3

    Exactly the same problem with me.
    Some other threads advice to remove fonts, clean the caches, remove add ins but nothing works consistenty, for some it looks like it works, for me it failed.
    What I did not try yet, was to move the Render files out of the malicious library to trash.

  • Converting doubles to unsigned shorts for grayscale BufferedImages

    I'm generating a slightly random array of doubles for use in defining pixel shades in grayscale BufferedImages, so I need to cast each double into a short so that my future DataBuffer can treat them as unsigned shorts. Right now the double values greater than 2^15 are becoming negative when casted, so how do I store it as unsigned?

    Thanks for the reply DrLaszloJamf. I need a Gaussian distribution of pixel shades, and the only Gaussian distribution generation functions I can find return doubles. Unfortunately I don't have time to write my own function to do the same with short values, but as implied by your second remark, I think the DataBuffer is doing with the shorts what I need it to. Thanks very much also for your answer to another post that showed me how to generate a grayscale BufferedImage using a DataBufferUShort in the first place!

  • Converting JPEG to BMP 1 bit depth

    Hi
    I need to convert JPEG to BMP 1 bit depth (monochromatic)
    I've used this code, but the result is always a 24 bit depth BMP...
    How can I do?
    JPEGDecodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(1, JPEGDecodeParam.COLOR_ID_GRAY);
    JPEGImageDecoder jd = JPEGCodec.createJPEGDecoder(myByteArrayInputStream, param );
    BufferedImage bufferedImage = jd.decodeAsBufferedImage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "bmp", baos);
    Thanks

    An application that you already have that can do the job is Preview. Open the file in Preview and do a Save As, seleting PICT as the end format.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • How to convert jpeg/imges to .avi file by applying Microsoft RLE Compression?

    I am doing windows based application for converting jpeg/bmp images into avi file by applying various compressions using C#.Net language. For that I have referred avifil32.dll.
    Here is the code:
    Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
    opts.fccType = (uint)Avi.streamtypeVIDEO;
    opts.fccHandler = (UInt32)Avi.mmioFOURCC('M', 'R', 'L', 'E');//Microsoft RLE
    opts.dwKeyFrameEvery = 2;
    opts.dwQuality = 75; // 0 .. 100
    opts.dwFlags = 0; // AVICOMRPESSF_KEYFRAMES = 4
    opts.dwBytesPerSecond = 0;
    opts.lpFormat = new IntPtr(0);
    opts.cbFormat = 0;
    opts.lpParms = new IntPtr(0);
    opts.cbParms = 0;
    opts.dwInterleaveEvery = 0;
    //get the compressed stream
    this.compressOptions = opts;
    int result = Avi.AVIMakeCompressedStream(out compressedStream, aviStream, ref compressOptions, 0);
    if (result != 0)
    throw new Exception("Exception in AVIMakeCompressedStream: " + result.ToString());
    SetFormat(compressedStream, 0);//To set format before the first frame can be written,and not to changed later.
    In this code I have used Microsoft RLE Compression i.e. MRLE. But Its not working, Getting exception becuase value of result coming zero.Other compressions such as IYUV,MSVC,CVID are working properly. So why MRLE is not working. Any solution for this? I
    have stucked with this problem from some days. Need a help.
    Thanks in advance.

    Hi Yenka,
    MRLE is not support on this forum. This forum is to discuss CLR programming issue. I recommend you reopen thread on desktop development forum. Refer to
    http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/home?category=windowsdesktopdev.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to convert jpeg files into word

    How to convert jpeg files into Word

    Hi Eugene,
    I don't think you can convert an image to a Word document, but you could place the JPEG into a Word document using the Insert > Object command in Word.
    For other questions relating to Word, you will probably have more luck getting an answer if you post on the Microsoft forums (we can help if you're using Acrobat, or another Adobe product, but you'll find the Word experts on the Microsoft forums.)
    Best,
    Sara

  • How to stop Preview from changing resolution when converting JPEGs into PDF

    I am combining several JPEGs of identical resolution into a PDF using Preview, using either the sidebar or Automator action (http://discussions.apple.com/thread.jspa?messageID=11893607). For some reason, Preview changes the resolution of the PDF so viewing it at actual size (100% zoom) is bigger and pixellated. Example: a 960x600 JPEG becomes approx 1355x845. I figured it had something to do with dpi and indeed if I do the calculation and open up each JPEG in Photoshop and resize (without resampling, i.e. without changing pixels) to 101.5, the resulting PDF is pretty close to what it should be. (Calculation = 1355/960 * 72dpi.) But the slight resize and recompression lowers quality, plus it's a huge pain to go through all of that for every image.
    This issue is the same for simple saving a single image, the combining and use of Automator script has no impact.
    My question, in summary: how do I get Preview to save a JPEG as a PDF without changing its resolution?

    I have the same problem. I have a bunch of scanned documents (jpeg), and have been trying to make them a multi page document, instead of 20+ images.
    Using the Automator "New PDF from Images" preview action v1.0, supplied by Apple with Snow Leopard, and I am able to convert the images to a PDF.
    Using these images, the first page being 1032 x 1600 pixels, and telling the automator action to +size each page to fit image+, I convert them into a PDF.
    Converted PDF is viewable here.
    The original JPG is clearly higher resolution than the PDF, and the PDF loses the crispness of the original scan. Even using "+size each page to fit image+" does not make the page the original image size.
    What's happening here, and does anyone know a better way to convert Jpegs to PDF on the Mac - and keep the image resolution? I don't care about files sizes here, but keeping resolution and maintaining quality.

  • How to convert jpeg to pdf for free?

    How to convert jpeg file to pdf file for free?

    You can also Download Acrobat XI Trial from the below link and Install it and use it for 30 days ....
    http://www.adobe.com/cfusion/tdrc/index.cfm?product=acrobat_pro&loc=us

  • How to convert jpeg to AI files

    I need to convert jpeg to AI files...

    And why do you need to do this? JPG images are used by every operating system and every image editing cataloging program made. Even Adobe Illustrator. Just put the JPG images in an illustrator project.
    I suggest you brush up on how to use Illustrator over at the Adobe website.

  • Converting JPEG files to DNG in Lightroom

    Is there any advantage to converting JPEG files to DNG when I import them into Lightroom? I am trying to maintain the quality of the file.
    Would it be better to save a JPEG file as a PSD file after I import it to use it in Photoshop and Lightroom?

    (Please pardon the change of subject:)
    Fred T. said, "If you are editing a JPEG in Photoshop going from Lightroom, let Lightroom create a TIFF. "
    I am wondering how to do this. I'm just an amateur and my non-SLR camera doesn't even save RAW images. ("Yup, need to take care of that one of these days.")
    My Preferences for "External Editors" (in my case Photoshop Elements 4.0) is set as: File Format: TIFF; Color Space: sRGB; Bit Depth: 16 Bits/component; Compression: ZIP.
    When I right-click on a file, and choose "Edit in Photoshop Elements 4.0.app", and pick Edit a Copy from the dialog box, the new file that is created and passed over to PE is a .JPG file not a .TIF file.
    I get the feeling that the functionality to create a TIFF, or a PSD, only works if my original image is RAW or DNG. But perhaps I am overlooking something???
    Life would be a lot easier if I could send the file to PE as a TIFF. At present, as a workaround, I tell LR to edit the original (so it doesn't create a copy), immediately Save-As in PE as a TIFF so I don't overwrite the original, and then when I'm done editing in PE, save the results (still TIFF). Once back in LR, I have to import the new file.
    Any Thoughts?

  • Converting jpeg to raw?

    So...  I am a bit of an amateur and have been shooting all of pictures in jpeg format.  I use Lightroom 4 and Photoshop Cs6 for editing them.  I am finally making the switch to raw format.  I would like all of my pictures to be in raw or dng to work better with lightroom, so here is my question.  Is it possible to convert jpeg fies to raw or dng?  Would it be a stupid idea to batch convert all of my jpegs into raw format?  Is it even possible?  I am kind of a new to this subject, so help me out.
    Thanks in advance

    Just some random thoughts, no real advice here...
    As long as you don't save over your original file, all editing is non-destructive. 
    If you open your original photo from a DNG, even though it may have a JPEG inside it, there's less chance you might accidentally just hit File - Save and write over it, because you can't File - Save into a DNG from within Photoshop proper.
    Also, if you would like to open your original photos through Camera Raw but don't want to use it for just any old JPEG, encapsulating the originals in DNG files will give you that distinction.
    -Noel

  • AUTOMATOR actions... converting Jpeg to PSD...

    Hi guys
    I am trying to find an action to convert about 10.000 photos and pictures from Jpeg to PSD... impossible to do it one by one, opening and saving using Photoshop CS... it'd take me forever!
    I was even able to download a pretty nice action from Apple called "Change File Format 1.3"... it's very good but it doesn't support PSD... only .TIFF files...
    I found another Automator Action for Photoshop CS "Photoshop Actions for Automator 1.0 " but it downloads as a .SIT file and I can't open it...
    Does anyone know where I can get an Automator Action to convert Jpeg to PSD files???
    Cheers

    Problem solved!
    Thank you guys!
    I downloaded Stuffit Express... so I was able to open "Photoshop Actions for Automator 1.0 "
    http://www.completedigitalphotography.com/index.php?p=339
    Great pack and I was able to open the .sit file and just dragged the actions to my Photoshop CS folder... and it immediatly showed up on AUTOMATOR...
    So, I just made a PSD copy of each Jpeg...
    Thank you

Maybe you are looking for