Create thumbnail using excessive memory

I have the following code to read an image (in a file) and create a thumbnail image, writing it to a file:
BufferedImage originalBufferedImage = ImageIO.read(new File(imagePathAndFileName));
int originalWidth = originalBufferedImage.getWidth();
int originalHeight = originalBufferedImage.getHeight();
double scale = 0;
if (((double)75 / originalWidth) <
((double)75 / originalHeight)) {
scale = (double)75 / originalWidth;
} else {
scale = (double)75 / originalHeight;
int width = (int)(originalWidth * scale);
int height = (int)(originalHeight * scale);
BufferedImage newBufferedImage = new BufferedImage(width, height, originalBufferedImage.getType());
Graphics2D graphics2D = newBufferedImage.createGraphics();
Canvas dummyObserver = new Canvas();
Image scaledImage = originalBufferedImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
graphics2D.drawImage(scaledImage, 0, 0, dummyObserver);
javax.imageio.ImageIO.write(newBufferedImage, fileType, new File(thumbnailPathAndFileName));
With a 1.9 Megabyte image, the call to ImageIO.read() tries to allocate 15 Megabytes of memory, as seen from the log (obtained in WebSphere 5.1 by setting an ALLOCATION_THRESHOLD limit):
Allocation request for 15085072 bytes
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:87)
at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:430)
at java.awt.image.Raster.createWritableRaster(Raster.java:965)
at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1146)
at javax.imageio.ImageReader.getDestination(ImageReader.java:2868)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:914)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:886)
at javax.imageio.ImageIO.read(ImageIO.java:1413)
at javax.imageio.ImageIO.read(ImageIO.java:1299)
Why does it use 15M to read in an image of 1.9M ? Is there a more efficient way to create thumbnail images?

A 15M image correponds to a 5M-pixel RGB 24-bit image. "ImageIO.read" decodes your 1.9M compressed jpeg (beeing roughly a 5Mpixel image, right?) file to a buffered image of some in-memory RGB 24bit format making it consuming 15M. You can get away with using less memory if you can find some ImageIO plugin returning a BufferedImage of type TYPE_CUSTOM with a compressed in-memory representation of the loaded image.
Regards,
Arvid

Similar Messages

  • Why does AVG Internet Security keep warning me that Firefox is using excessive memory and advisin me to close it and reopen?

    My browser was open and I was on Facebook. A message appeared from AVG Internet Security 2012, which is operating on my computer, telling me that FireFox was using excessive memory -- "260 MB of memory" and suggesting I close FireFox and reopen.
    This has happened several times; also when I was on CNN and Yahoo webpages.

    How much RAM do you have?
    300MB is a lot if you only have 512MB, but not too much if you have 1 or 2 GB, or more.
    http://blogs.avg.com/community/avg-feedback-update-week-44/
    See - 3. AVG Advisor = Disable AVG Advisor performance notifications <br />
    or try using the "Change when these notifications appear" and set a higher threshhold

  • Creating thumbnails using jsf

    Hi,
    I want to create thumbnails using jsf and facelets so that I can view the images from a folder which is queried by a jsf pages passing a argument to the page.

    I think fail is not the answer.If you donot have solution you should not waste ur time.

  • Since installing the last update I am getting warnings through AVG that friefox is using excessive memory - 215 MB. Please provide input as to whteher this is a matter of concern becuase the window is coming up constantly.

    I am on a dell 620 laptop. Every time I get on Firefox, an AVG window is popping up saying that excessive memory is being used (215 MB) and it recommends that I log out and log back in for faster processing. Logging out does not make a difference. The last update also disabled my AVG tool bar from the internet screen which I am not sure matters much, but I am concerned about the excessive memory use warning. Can you please provide me guidance about this matter?

    Thanks but I have no idea how to do that and don't know the purpose of the add- ons or what is considered critical in the updates so that is outside of my knowledge level and comfort. How do I find out what is critical in the update without devoting a major chunk of my life to it? This is getting frustrating from my perspective. I am going to contact AVG and ask them how this pop up is gauging what to interpret critical memory use. If you have any other thoughts they are appreciated

  • Why Does Safari Use Excessive Memory with Gmail?

    I am running Safari 7.0.1 along with Maverics (10.9.1) on a 2011 MacBook Air with 4 GB of memory. Just recently I have begun to notice excessive memory usage when using Gmail. I have iStat Menus as well as something called MemoryKeeper so I can monitor memory use in real time.
    The table below shows numbers taken from Activity Monitor with each of the sites running in a single tab.  The Safari Web Content is through the roof with Gmail compared to My Yahoo or indeed with any other single site. In Gmail it starts out above 500 MB and slowly comes down to the lower end indicated if I do nothing. If I open tabs with both My Yahoo and Gmail, I sink below 100 MB and if I have three tabs open I'm heading to zero. As far as I can tell, the excessive memory useage only occurs with Gmail.
    Process
    Yahoo
    Gmail
    Safari
    156 MB
    167 MB
    Safari Web Content
    96 MB
    531-338 MB
    Kernel Task
    464 MB
    464 MB
    Free
    662 MB
    210 MB
    Typically I will close Safari and start it again if I get much below 100 MB. I usually have to close Safari at the end of the day to refresh it for the next day. This has only become a problem within the last month or so, and I am at a loss to explain it. I thought it might be Mavericks related (though I have been running Mavericks since its release), but then the Safari I have on my 5 year old Mac Mini running Snow Leopard gives me similar results.
    When I run Google Chrome I don't have any of these problems. Indeed, though it is not my preference, I am having to use it more and more for day to day activities or I have to stick with one tab if I am going back and forth between Gmail and other sites. I have not seen this problem reported elsewhere, so I have to believe there is something going on in my system. I have cleared the cache one time on both systems, but that doesn't seem to have made any difference. I would appreciate any comments or suggestions.
    -Bill

    I would not have even tried this app had I not heard about it on the Mac Rountable podcast (episode #222), where it received favorable comments from otherwise knowledgeable people. It also has a 4.5 star rating on the Mac App Store with 706 5-Star ratings out of 1,049. If you add up the 5-Star and 4-Star ratings you get close to 1,000 favorable rates right there. I have to wonder if people really know what's going on. Since the most obvious detrimental effects for me were centered around using Safari with Gmail on Mavericks, others must not be using that lethal combination. As I mentioned, using Google Chrome does not seem to have any obvious deliterious effects.
    Well, there's going to be one more 1-Star rating reflecting my experience.
    -Bill

  • Flash Player uses excessive memory when in use for a long time.

    Good morning,
    I'm using firefox with flash player viewing streaming video from www.bloomberg.com/tv/us.The longer this runs the more user memory it uses (from Windows Task Manager, Processes tab).
    I had this site running for about 4 houres and at that time it was using 1.7 GB memory and the video was  getting eratic. This shows up in a file called "plug-incontainer.exe". I terminated the process and flash player disappeared with a message the said "flash player has crashed".
    It doesn't matter if I use Flash Player 10 or 11 or Firefox 3.6 or 21.01.
    This also occurs with Internet explorer Ver. 8 except it's manifested in a second instance of Iexplore. Same creeping memory useage.
    OS is Windows Xp sp2, processor is a 3GHz hyperthreading P4 with 2GB of installed memory.
    I really don't think it should do this.
    [email protected]

    Was the computer turned off or asleep? It won't hurt to have it taken off. Normally I wouldn't worry about it unless it was going to be a few more months.
    Mort

  • Getting Bitmaps from files uses excessive memory

    When I load a jpg picture as a bitmap I lose a lot of memory that I am unable to recover.
    I use the GetBitmapfromfile, the GetBitmapInfo, then GetBitmapData, then DiscardBitmap.
    after this I have about 120 M of memory (for a 5 M pixel image) missing that I cannot recover.  The size of this lost memory is proportional to the number of pixels in the image.
    Solved!
    Go to Solution.

    Hi Kelly
    Thanks for your response.  I am using CVI 8.1.0.  I detect the memory through using windows task manager. 
    My real problem is that my final application is using too much memory and going into virtual memory too much, when I have been tracing my memory usage I have a lot of memory unaccounted for and I cannot get it back.  This happens when I load the bitmap, and cannot be recovered untill my program is stopped.
    I have attached some code with pictures to try (use the 2 DSCxxx for comparision to my run).  I have also enclosed screen shots so you can see how the memory is used on my PC.  Sorry for the large file size, I thought it best to send the same sample photos I have been using.
    Attachments:
    CVI Test.zip ‏4944 KB

  • 3 management servers (500 agents) are using excessive memory

    Hi,
    Our Opsmgr 2012 R2 UR2 environment has got 3 management server for 500 agents
    We got a few large MP's like:
    Veeam, Cisco UCS (divided on two management servers)
    One management server which has got only reporting service and the webconsole, without agents, is losing 16 gig of memory a day. The next day the server has consumed all the memory and we need to restart the server.
    How can a new R2/UR2 management server consume so much memory on a server who communicates with reportings service which isn't used much and with a webconsole we don't use much.
    Kind regards,
    André

    Hi,
    Would you please look into your task manager and find out the corresponding process that eat up most memory.
    In addition, hope the below article can be helpful for you:
    Troubleshooting Windows Performance Issues: Lots of RAM but no Available Memory
    http://blogs.technet.com/b/mspfe/archive/2012/12/06/lots-of-ram-but-no-available-memory.aspx
    Regards,
    Yan Li
    Regards, Yan Li

  • Recently upgraded to 7.0.1 and twice now have had warning that Firefox using excess memory.

    Windows XP with 2Gb Ram

    As it sounds like you know what you're doing, you know the way that iTunes works. However, because you have not archived/exported (please correct me if you have) your library. There should only be a slight difference between the two.
    If you have not already been here, this also has some solutions.
    http://www.apple.com/support/itunes/musicstore/lostmusic/
    Zach

  • Firefox doesn't close but hangs in the background after closing it using up excessive memory up to 2gb.

    When Firefox 8 loses connection to certain websites and I have to close it from the lower taskbar, it hangs in the background on task manager using excessive memory even after it is closed. I have seen it use up to 2gb of memory while closed but still hanging in the background in task manager. My computer slows down and when I try to open another browser window the little loading icon goes around and around so I check to see what is making it so slow. It is always firefox 8 hanging in the background using memory. I have 8gb of ddr2 memory on this 64 bit computer it shouldn't be slowing down because of a browser bug but it does.

    From what I have been reading from other posts on this forum, the
    issue may be caused by the clear history settings.
    Press the '''<Alt>''' or '''<F10>''' key to bring up the tool bar.
    Followed by;
    Windows; '''Tools > Options'''
    Linux; '''Edit > Preferences'''
    Mac; ''application name'' '''> Preferences'''
    Then '''Privacy'''.
    The button next to '''History''', select '''Use Custom Settings'''.
    At the bottom of the page, turn on '''Clear History When Firefox Closes.'''
    At the far right, press the '''Settings''' button. Turn on ONLY '''Cache''' and
    '''Form And Search History''' leaving the others off.
    This is not a cure but will make it easier if Firefox locks up.
    '''https://support.mozilla.org/questions/997866?esab=a&s=&r=1&as=s''' {web link}

  • What is the fastest way to create thumbnails in CS6?

    Hi All...
    I wanted to know if there is a certain way you can take larger images and have them shrink down to a thumbnail size in an automated fashion?  Instead of having to load each image and change the dimensions and export the image as a thumbnail?  I'm using Web Premium CS6 and also have Lightroom 4.  There must be a less tedious method to create a small size and a large size image...
    Any thoughts?

    You can do this easily using Actions and Batching in Photoshop CS6.
    Here are two video tutorials on how to do this in CS6, specifically for creating thumbnails; using actions and batching actions. The guys is a little long-winded but is very comprehensive.
    And here's an article on how to do the same thing. It's from 2007 but explains the process nicely.

  • Accessing or creating thumbnail images of pages to use in navigation

    In Bridge I can scroll through the Indesign pages by scrolling through the thumbnail images without opening the Indesign file.
    Is it possible to access those thumbnails so that I can use them as page navigation buttons in the Indesign file, or is there another way to create a thumbnail of the pages to reuse as buttons?
    thanks

    In the thread here I mention an external utility I wrote to extract the JPEG thumbnails that InDesign creates for use in Bridge. If you don't use Windows, google a bit to find a Javascript that does the same. (The difference is, you need to run the JS from within InDesign; my program works without.)
    Both the script and the program can only extract what's in the file: http://help.adobe.com/en_US/indesign/cs/using/WSa285fff53dea4f8617383751001ea8cb3f-6d51a.h tml
    (Similar to the above, a PDF may contain a per-page thumbnail, but I have no idea on how to extract those.)

  • Adobe Reader XI (11.0.08) doesn't create thumbnail (bitmap) using Microsoft Interface IExtractImage -- Extract on Windows Server 2008 R2, when exe to generate thumbnail is launched from Windows service.

    Adobe Reader XI (11.0.08) doesn't create thumbnail (bitmap) using Microsoft Interface IExtractImage --> Extract on Windows Server 2008 R2, when exe to generate thumbnail is launched from Windows service.
    But if exe is launched as standalone, then interface IExtractImage --> Extract, gives Bitmap to generate thumbnail of PDF document.
    Above problem occurs only for PDF documents, if we tried same with other software like CAD -CATIA it works without any problem.
    Is there any security concerns form PDF side, which doesn't allow to generate Bitmaps, if exe to generate it is launched form Windows service.

    It might be deliberate, Acrobat and Reader software is not intended to run in a service environment.

  • AVG reports excessive memory used by Aurora

    At various intervals my free AVG reports excessive memory used by Aurora, and suggests closing it.

    -> [[Firefox consumes a lot of CPU resources]]
    * http://kb.mozillazine.org/Firefox_CPU_usage
    -> [[High memory usage]]
    * http://kb.mozillazine.org/Reducing_memory_usage_-_Firefox
    Check and tell if its working.

  • Creating Thumbnails with ImageIO or JAI?

    Hello,
    Could anyone advise between the clases available in ImageIO and the JAI.
    Which use the least amount of memory, and is quickist in creating thumbnails from an jpeg, or gif image?
    My thought was the JAI would be quicker, and perhaps uses less memory or better at release memory.
    I would much appreciate the members guidance.
    Thanks

    Further to this, I first thought the problem was probably something to do with the Xserver requirement for java.awt.Toolkit, but as you can see from the code, an image is loaded and scaled (as far as I can tell) with no problems - its just encoding it and writing it back out that causes problems.

Maybe you are looking for

  • All mozilla apps crash on startup after upgrade to 10.4.11

    Hello, Title says it all. I tried reinstalling each after the update to no avail. Here's the report after Firefox 20.0.0.11 and Thunderbird 2.0.0.9 crash on startup, respectively: Firefox: Date/Time: 2008-01-09 01:12:37.338 -0800 OS Version: 10.4.11

  • Missing package information

    I changed my bt package effective from today and the order information says completed.  It should be unlimited broadband and unlimited anytime phone calls.   However mybt says weekend/evening calls only(which I've never had).  I have read stephanieg'

  • Does XE support Bitmap Indexes?

    Hi, I am trying to create a bitmap index in XE and getting the following error: ORA-00439: feature not enabled: Bit-mapped indexes I am guessing this is only available in the enterprise editions of the database or is there some way i can enable this

  • Crystal Report Grouping Formula

    Experts, In Crystal repot how can we have Grouping formula basis, i.e there are two coulmns 1. GRPO Doc No 2. GRPO Doc No (Has GRNA) now if column 2 has value it should do grouping with this or if column 1 has value then grouping should be done on co

  • VK11 Condition types for taxes

    Hey, I'm attaching the print screen of Vk11 for taxes. I don't understand what is the use of taxcode(highlighted) on the image. I have seen F1, but it doesn't make any sense to me.... I'm putting the tax rate % in the amount field... What is the use