Capture Image Of A Very Large JPanel

Below is some code used to save an image of a JPanel to a file...
    int w = panel.getSize().width;
    int h = panel.getSize().height;
    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics graphics = image.getGraphics();
    // Make the component believe its visible and do its layout.
    panel.addNotify();
    panel.setVisible(true);
    panel.validate();
    // Draw the graphics.
    panel.print(graphics);
    // Write the image to a file.
    ImageFile imageFile = new ImageFile("test.png");
    imageFile.save(image);
    // Dispose of the graphics.
    graphics.dispose();This works fine but my problem is that I am trying to save what may be a very large JPanel, perhaps as large as 10000x10000 pixels. It doesn't take long for the java heap to be used up and an exception to be thrown.
I know I can increase the heap size of the JVM but since I can't ever be sure how large the panel may be that's a far from ideal solution.
So the question is how do I save an image of a very large JPanel to a file?

1) Does the OoM happens while instantiating the buffered image, (which probably tries to allocate a big continuous native array of pixels)?
Or the Graphics object (same reason, though the Graphics is probably just an empty shell over the big pixel array)?
2) In which format do you need to save the image? Do you only need to be able to read it again in your own program?
If yes to both questions, then a pulled-by-the-hair solution coud be to instantiate your own Graphics subclass (no Buffered Image), whose operations would save their arguments directly to the image file, instead of into a big in-memory model of the panel image.
If the output format is a standard one though (GIF, JPG,...), then maybe your custom Graphics's operations could contain the logic to encode/compress as much as possible of the arguments into an in-memory bytearray of the target format?
I'm not very confident though; I d'ont know the GIF or JPEG encoding, but I suspect (especially for JPEG) that you need to know the "whole" image to encode it properly.
But if the target format supports encoders that work on the fly out of streams of bytes (e.g. BMP ) then you can use whatever compress/uncompress technique you see fit (e.g. RLE ): you know the nature of the panels, you may be aware of some optimizations you may perform wrt pixels storage. prior to encoding (e.g., bug empty areas, predictable chessboard pattern, black-and-white palette,...).
Edited by: jduprez on Sep 19, 2009 7:33 PM

Similar Messages

  • What is the optimum core configuration for a new Mac Pro to process and manipulate very large (80 megapixel) images using PhotoShop and Camera Raw?

    Hello:
    I will be using creative techniques to process and manipulate a large number (hundreds) of very large (80 megapixel) images captured using a medium format digital back (Phase One IQ180).
    Final output will be digital fine art imagery printed using an Epson 11880 at large sizes (up to 60 inches x ?), retaining the highest possible quality and resolution. I will be using Adobe CC PhotoShop and Camera RAW as well as Capture One software. PhotoShop filters will be used extensively.
    The Mac Pro needs to be optimized for the above purpose and be useful for at least five years. I plan to max out all the other options (RAM, graphics cards, storage). Performance is more important than cost.
    The few discussions I have found that mention optimum core configurations seem to lean toward 6 or 8 (but likely are not taking into consideration my need for manipulating a large number of very large files), so I am looking to this foum for opinions.
    Thank you,
    Kent

    See if this helps
    http://macperformanceguide.com/index_topics.html#MacPro2013

  • Please help!! "Can't open the illustration. This artwork contains a very large image that can not...

    Hi all, I am subscribing Illustrator CS6 16.0.0 and using it on Windows 7.
    Few days ago I was working with one file, I saved it successfully and now when I'm trying to open it an error message occures "Can't open the illustration. This artwork contains a very large image that can not be read on this version of AI. Please try with 64-bit version." and ALMOST ALL of the objects (vector) are missing as if they were deleted!
    It's kind of strange since I created the file with the same program and everything was working properly before.
    Please Please advice further steps for recovering my file.

    Thank you so much! the file is recovered (as well as my emotional state )
    The finding of the day - apparently I have two versions of AI in my PC!

  • Editing very large images

    I have several very large images that require minor editing. The tasks that I require are only basic rotation, cropping, and maybe minor color adjustments.
    The problem is that the images range from 20780 x 15000 px down to 11150 x 2600 px.
    With images this size, when I try to perform any operation on the entire image, like a 3 deg rotation, fireworks simply times out. Maybe it is because it can't generate the preview image at that size, maybe it simply can't calculate the image at that size. If it is just the preview image, is there a way to lower the quality (say, jpeg quality of 5%) of the preview image only but when I export the image, I can keep it at 100%?
    Thank you,
    -Adam
    (Yes, I did search, but the forums search seemed mildly useless and engine results consistently returned nothing)

    Fireworks is not designed to work with images of this size. It's a screen graphics application. Photoshop would be a better option here, or other software designed for working with high resolution files.
    Jim Babbage

  • What is the best way to handle very large images in Captivate?

    I am just not sure the best way to handle very large electrical drawings.
    Any suggestions?
    Thanks
    Tricia

    Is converting the colorspace asking for trouble?  Very possibly!  If you were to do that to a PDF that was going to be used in the print industry, they'd shoot you!  On the other hand, if the PDF was going online or on a mobile device – they might not care.   And if the PDF complies with one of the ISO subset standards, such as PDF/X or PDF/A, then you have other rules in play.  In general, such things are a user preference/setting/choice.
    On the larger question – there are MANY MANY ways to approach PDF optimization.  Compression of image data is just one of them.   And then within that single category, as you can see, there are various approaches to the problem.  If you extend your investigation to other tools such as PDF Enhancer, you'd see even other ways to do this as well.
    As with the first comment, there is no "always right" answer.  It's entirely dependent on the user's use case for the PDF, requirements of additional standard, and the user's needs.

  • How to save FrameworkElement as very large raster image?

    I have to save my FrameworkElement as
    very large raster image. For now I use the RenderTargetBitmapclass
    and a BitmapEncoder,
    in this way:
    RenderTargetBitmap bmp = new RenderTargetBitmap(ElementWidth, ElementHeight,
         90, 96, PixelFormats.Default);
    bmp.Render(MyElement);  // OutOfMemoryException here
    PngBitmapEncoder encoder = new PngBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(bmp));
    using (var stream = File.Create(filePath))
    { encoder.Save(stream); }
    Where ElementWidth and ElementHeight are large numbers (about 10000x6000). But with this solution there's a OutOfMemoryException when i try to Render my
    element.
    There are other ways to do what I need (without causing an OutOfMemoryException)? Thanks.

    Following link may help you
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c5e31d70-08d1-4402-8016-0a0b7af49b04/
    Gaurav Khanna | Microsoft VB.NET MVP

  • Very large responsive background images

    Just a quick question with these - for example the page here:
    http://www.destinationsshow.com/
    Not so much the CSS, but the knack to get such a large image that isn't too big in terms of file size, but still retains pretty good quality when very large?
    Also, I noticed on that example the original image is actually made up of two copies of the image with one mirrored vertically.
    You can see what I mean here:
    http://www.destinationsshow.com/images/splash_2014_bg.jpg
    Is that significant?
    Thanks for any pointers.

    Your example uses two different background images
    The mobile one is 18 KB
    420px × 667px.
    The desktop one is much bigger, 198 KB
    2,000px × 2,666px
    In my example below,  140 KB
    900px × 675px.
    http://alt-web.com/TEST/Resizable-BG.shtml
    Nancy O.

  • Creating a custom DataBuffer for very LARGE images

    I would like to work with very large images (up to 100MB) in an application.
    Only for image manipulating, not rendering for screen.
    My idea is to write my own DataBuffer which use Hard Drive,maybe with some "intelligent" swapping.
    But At first performance doesn�t matter.
    I try this:ColorModel cm = ColorModel.getRGBdefault();
    SampleModel sm = cm.createCompatibleSampleModel(w,h);
    DataBuffer db =  new  myDataBufferInt(size);
    WritableRaster raster = Raster.createWritableRaster(sm,db,null);But somebody don�t like myDataBuffer
    and of course it is type DataBuffer.TYPE_INTthrows:java.awt.image.RasterFormatException: IntegerComponentRasters must haveinteger DataBuffers
    at sun.awt.image.IntegerComponentRaster.<init>(IntegerComponentRaster.java:155)
    at sun.awt.image.IntegerInterleavedRaster.<init>(IntegerInterleavedRaster.java:111)
    at sun.awt.image.IntegerInterleavedRaster.<init>(IntegerInterleavedRaster.java:78)
    at java.awt.image.Raster.createWritableRaster(Raster.java:980)
    public  class myDataBufferInt extends DataBuffer {
    public myDataBufferInt(int size) {
            super(TYPE_INT,size);
        . . . }The question is how to manage large image?
    What kind of subclasses I have to write?
    Thank you all
    P.S: I don�t want to use: java -Xmsn -Xmxn

    i have the same problem let me know please if you have an answer?

  • Display of the images became very large in macbook air, display of the images became very large in macbook air

    suddenly the display became very large. it seems like the dsiplay for  the handicap as if in ipad. How to restore to normal display? Thank

    This link may help http://docs.info.apple.com/article.html?path=Mac/10.7/en/mchlp2368.html

  • My screen image got very large, like it was super zoomed.

    I could open it only by holding one finger on the start of the swipe bar, then carefully moving the screen left with the other until the end of the bar came in view.  I turned it off, held both the power and stqrt button down, no change.  I plugged it into itunes, updated to 4.3.3, and it worked normal, except the contacts app is in a very large font. I can't get the font smaller in contacts now.

    Hi,
    Try checking the following settings for your font size:
    Press "Settings" on your home screen ( a Silver icon with Gears)
    Then choose "General," when you are in general, scroll to the bottom of the page, and choose "Accessibility"
    By default, all the settings should say "Off," if not, try choosing each setting pages to turn them off.
    cwdlin

  • Problem with capture image from wc

    hi all, i want to capture image from my webcam and play it, but it's not work
    please help me, here's code
    public class Demo extends JFrame {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Demo demo = new Demo();
         public Demo() {
              super();
              int a=30;
              final JPanel panel = new JPanel();
              getContentPane().add(panel, BorderLayout.CENTER);
              setVisible(true);
              DataSource dataSource = null;
              PushBufferStream pbs;
              Vector deviceList = CaptureDeviceManager.getDeviceList(new VideoFormat(null));
              CaptureDeviceInfo deviceInfo=null;boolean VideoFormatMatch=false;
              for(int i=0;i<deviceList.size();i++) {
              // search for video device
              deviceInfo = (CaptureDeviceInfo)deviceList.elementAt(i);
              if(deviceInfo.getName().indexOf("vfw:/")<0)continue;
              VideoFormat videoFormat=new VideoFormat("YUV");
              System.out.println("Format: "+ videoFormat.toString());
              Dimension size= videoFormat.getSize();
              panel.setSize(size.width,size.height);
              MediaLocator loc = deviceInfo.getLocator();
              try {
                   dataSource = (DataSource) Manager.createDataSource(loc);
                   // dataSource=Manager.createCloneableDataSource(dataSource);
                   } catch(Exception e){}
                   Thread.yield();
                   try {
                        pbs=(PushBufferStream) dataSource.getStreams()[0];
                        ((com.sun.media.protocol.vfw.VFWSourceStream)pbs).DEBUG=true;
                        } catch(Exception e){}
                        Thread.yield();
                        try{dataSource.start();}catch(Exception e){System.out.println("Exception dataSource.start() "+e);}
                        Thread.yield();
                        try{Thread.sleep(1000);}catch(Exception e){} // to let camera settle ahead of processing
    }

    iTool wrote:
    hi all, i want to capture image from my webcam and play it, but it's not workThat's a very descriptive error message, "it's not work". Everyone on the board will certainly be able to help you out with that.
    The first error I see is that you're using the CaptureDeviceManager in an applet. If T.B.M pops in here, he can tell you why that's going to be a CF 99% of the time.
    The other error I see is that your code looks absolutely nothing like any working JMF webcam capture code I've personally ever seen.
    Lastly, the big one, even if you were somehow capturing video magically, you're not even trying to display it...so I'm not entirely sure why you expect to see anything with the code you just posted.
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/JVidCap.html]
    Your best bet would be starting over and using the example code from the page linked above.

  • Setting resolution, deciding file type, for very LARGE Canvas prints. 36MP camera.

    Okay, so I noticed my lightroom was on 240 PPI resolution. I changed it to 300 because I read 300 was for standard prints. What would I need to set the export to in the resolution box for a very large Canvas?
    Is it better to choose Tiff instead of Jpeg for prints of this quality, if not then what should I choose?
    I am using a Sony A7R full frame 36.4MP and with some of the sharp Zeiss lens there is really no pixelation that noticeable when I zoom in 100 percent. Of course the A7R is being said to be one of the best Sensors on the market today. It's supposed to be like the Nikon D800E, but apparently it has some advantages.
    In other words, I want to export in as high of quality as possible for the Canvas. File size is not an issue.

    Changing the resolution setting does absolutely nothing to the digital image. This is a common misconception. The only thing that counts in the digital image is the pixel dimensions. Regardless of what the PPI setting is (240, 300, 600, whatever) the image still has the same number of pixels. To determine what you need for a print of any size it is necessary to multiply the inches by the desired pixels per inch. Suppose you want a 16 x 20" print at 300 pixels per inch. The math would be something like this:
    300x16 = 4800 pixels
    300x20 = 6000 pixels
    So to print a 16 x 20" print you would need an image that is 4800 x 6000 pixels. And the PPI setting can be anything you want it to be because it has no effect on the image.

  • Unable to copy very large file to eSATA external HDD

    I am trying to copy a VMWare Fusion virtual machine, 57 GB, from my Macbook Pro's laptop hard drive to an external, eSATA hard drive, which is attached through an ExpressPort adapter. VMWare Fusion is not running and the external drive has lots of room. The disk utility finds no problems with either drive. I have excluded both the external disk and the folder on my laptop hard drive that contains my virtual machine from my Time Machihne backups. At about the 42 GB mark, an error message appears:
    The Finder cannot complete the operation because some data in "Windows1-Snapshot6.vmem" could not be read or written. (Error code -36)
    After I press OK to remove the dialog, the copy does not continue, and I cannot cancel the copy. I have to force-quit the Finder to make the copy dialog go away before I can attempt the copy again. I've tried rebooting between attempts, still no luck. I have tried a total of 4 times now, exact same result at the exact same place, 42 GB / 57 GB.
    Any ideas?

    Still no breakthrough from Apple. They're telling me to terminate the VMWare processes before attempting the copy, but had they actually read my description of the problem first, they would have known that I already tried this. Hopefully they'll continue to investigate.
    From a correspondence with Tim, a support representative at Apple:
    Hi Tim,
    Thank you for getting back to me, I got your message. Although it is true that at the time I ran the Capture Data program there were some VMWare-related processes running (PID's 105, 106, 107 and 108), this was not the case when the issue occurred earlier. After initially experiencing the problem, this possibility had occurred to me so I took the time to terminate all VMWare processes using the activity monitor before again attempting to copy the files, including the processes mentioned by your engineering department. I documented this in my posting to apple's forum as follows: (quote is from my post of Feb 19, 2008, 1:28pm, to the thread "Unable to copy very large file to eSATA external HDD", relevant section in >bold print<)
    Thanks for the suggestions. I have since tried this operation with 3 different drives through two different interface types. Two of the drives are identical - 3.5" 7200 RPM 1TB Western Digital WD10EACS (WD Caviar SE16) in external hard drive enclosures, and the other is a smaller USB2 100GB Western Digital WD1200U0170-001 external drive. I tried the two 1TB drives through eSATA - ExpressPort and also over USB2. I have tried the 100GB drive only over USB2 since that is the only interface on the drive. In all cases the result is the same. All 3 drives are formatted Mac OS Extended (Journaled).
    I know the files work on my laptop's hard drive. They are a VMWare virtual machine that works just fine when I use it every day. >Before attempting the copy, I shut down VMWare and terminated all VMWare processes using the Activity Monitor for good measure.< I have tried the copy operation both through the finder and through the Unix command prompt using the drive's mount point of /Volumes/jfinney-ext-3.
    Any more ideas?
    Furthermore, to prove that there were no file locks present on the affected files, I moved them to a different location on my laptop's HDD and renamed them, which would not have been possible if there had been interference from vmware-related processes. So, that's not it.
    Your suggested workaround, to compress the files before copying them to the external drive, may serve as a temporary workaround but it is not a solution. This VM will grow over time to the point where even the compressed version is larger than the 42GB maximum, and compressing and uncompressing the files will take me a lot of time for files of this size. Could you please continue to pursue this issue and identify the underlying cause?
    Thank you,
    - Jeremy

  • XML Report comes up as blank when a very large sequence is run

    Forum,
    We have multiple test sequences which me mix and match to do testing on different producst in our product line. We have no issues when we are working with small sequences ( small sequences : Which generate reports upto 12-50MB ). However when the sequences become large ( ~100-200 tests at one go , we get a blank report with the following text: 
    Begin Sequence:
    No Sequence Results Found
    We notice this typically for report sizes 60MB and more. Is there a limit to how much teststands result collection memory can store ? 
    My predominant report options 
    -- On the fly reporting disabled
    -- XML - expand.xsl selected
    The same set of settings do not make any difference for smaller reports, but give error for larger sequences - So I suspect its something to do with size of report being generated ! 

    I created a simple sequence file which had a 100 Pass/Fail steps using the None Adaptor. These 100 steps in the form of 10 SequenceCall steps each performed 10 Pass/Fail step was placed in a For loop in the MainSequence. The loop was set to run 1000 iterations. The ReportOptions were set for XML horizonal, On the Fly enabled.
    This I set running. Explorer was open at the folder where the result file was being stored. Two files were generated, the actual result file and a temporay file. I also had the Taskmanager open to monitor the performance.
    As the result file got larger, about 20MB, I noticed that the size of the file was first set to zero and the data was written to the file. (It seemed like the file was deleted and generated each step result time). I also noticed that as the file got larger and larger, the storing of the step results was having an effect on the performance of the Test Sequence execution.
    I left this running over night and sometime later the execution crashed. (see attached image). Before closing the dialog, I checked explorer to see what the state of the result file was. The both files was empty.
    I repeated the run but this time the number of iteration was set to 500, again the execution crashed but this time the result file did have some data, rather a lot of data, over 50MBs.
    I tried to open the file to check the contents but unfortunately my PC didn't seem to beable to handle a file of that size, as it was taking a long time to load, so I kill the process.
    I dont think changing the iterations from 100 to 500 had anything to do with the getting the results on the second. I just think the point were it crashed was slightly different allowing the result to be transferred back to the file.
    It would be interesting to find out whats going on the On the fly routine.
    It also seems that On the fly seems no better that normal reports generation.  It also seems pointless generating a very large file of results and that generating smaller files would be the better way to go. Using HTML or XML a top level report file could be used to link all the smaller files together.
    Regards
    Ray Farmer 
    Regards
    Ray Farmer

  • Can iCloud be used to synchronize a very large Aperture library across machines effectively?

    Just purchased a new 27" iMac (3.5 GHz i7 with 8 GB and 3 TB fusion drive) for my home office to provide support.  Use a 15" MBPro (Retina) 90% of the time.  Have a number of Aperture libraries/files varying from 10 to 70 GB that are rapidly growing.  Have copied them to the iMac using a Thunderbolt cable starting the MBP in target mode. 
    While this works I can see problems keeping the files in sync.  Thought briefly of putting the files in DropBox but when I tried that with a small test file the load time was unacceptable so I can imagine it really wouldn't be practical when the files get north of 100 GB.  What about iCloud?  Doesn't appear a way to do this but wonder if that's an option.
    What are the rest of you doing when you need access to very large files across multiple machines?
    David Voran

    Hi David,
    dvoran wrote:
    Don't you have similar issues when the libraries exceed several thousand images? If not what's your secret to image management.
    No, I don't  .
    It's an open secret: database maintenance requires steady application of naming conventions, tagging, and backing-up.  With the digitization of records, losing records by mis-filing is no longer possible.  But proper, consistent labeling is all the more important, because every database functions as its own index -- and is only as useful as the index is uniform and holds content that is meaningful.
    I use one, single, personal Library.  It is my master index of every digital photo I've recorded.
    I import every shoot into its own Project.
    I name my Projects with a verbal identifier, a date, and a location.
    I apply a metadata pre-set to all the files I import.  This metadata includes my contact inf. and my copyright.
    I re-name all the files I import.  The file name includes the date, the Project's verbal identifier and location, and the original file name given by the camera that recorded the data.
    I assign a location to all the Images in each Project (easy, since "Project" = shoot; I just use the "Assign Location" button on the Project Inf. dialog).
    I _always_ apply a keyword specifying the genre of the picture.  The genres I use are "Still-life; Portrait; Family; Friends; People; Rural; Urban; Birds; Insects; Flowers; Flora (not Flowers); Fauna; Test Shots; and Misc."  I give myself ready access to these by assigning them to a Keyword Button Set, which shows in the Control Bar.
    That's the core part.  Should be "do-able".  (Search the forum for my naming conventions, if interested.)  Or course, there is much more, but the above should allow you to find most of your Images (you have assigned when, where, why, and what genre to every Image). The additional steps include using Color Labels, Project Descriptions, keywords, and a meaningful Folder structure.  NB: set up your Library to help YOU.  For example, I don't sell stock images, and so I have no need for anyone else's keyword list.  I created my own, and use the keywords that I think I will think of when I am searching for an Image.
    One thing I found very helpful was separating my "input and storage" structure from my "output" structure.  All digicam files get put in Projects by shoot, and stay there.  I use Folders and Albums to group my outputs.  This works for me because my outputs come from many inputs (my inputs and outputs have a many-to-many relationship).  What works for you will depend on what you do with the picture data you record with your cameras.  (Note that "Project" is a misleading term for the core storage group in Aperture.  In my system they are shoots, and all my Images are stored by shoot.  For each output project I have (small "p"), I create a Folder in Aperture, and put Albums, populated with the Images I need, in the Folder.  When these projects are done, I move the whole Folder into another Folder, called "Completed".)
    Sorry to be windy.  I don't have time right now for concision.
    HTH,
    --Kirby.

Maybe you are looking for

  • How do I get rid of BB App World Notification?

    I just got my BB last night, so I'm very new to this, but I did the update on the BB App World, and there were some apps that I did not want (such as Yahoo Messenger) that it kept coming up that there was an update available for... so I uninstalled t

  • I REGRET OVERCLOCKING!

    Today is the saddest day in my life. My Barton 3000+ processor has died on me yesterday night when I was trying to overclock it. This is what I did: 1) I set the multi at 11 and raised the FSB to 200MHz, saved settings and exit.     --System didn't p

  • Lion not saving settings, iTunes not working, iPhoto not repairing

    having a ton of issues and not sure if it's upgrading to Lion, updating iTunes or something else causing the problem. When I'm logged in as the main user getting a ton of problems including; 1)  no matter which box I check or uncheck or which windows

  • Cost to replace internal DVD drive?

    (I tried posting this as a reply to a related question No luck.) DVD's eject from my built-in drive after ~30 seconds, although a blank DVD does not. CDs appear to work okay. I've tried resetting PRAM and SMS, but to no avail. I've read other related

  • Viewing many windows on one screen

    Hi, I would like to be able to view a few windows on one screen so I don't have to minimize & maximize etc when working with a few things. Someone set it up on my computer using hot corners but I didn't like those corners so I turned them off. Any ad