Help redrawing large image

I have a 600x600 applet that redraws each pixel (drawing the mandelbrot set).
Right now (just using a for loop and paint() method) it swipes down drawing the pixels and takes a couple seconds.
I tried to draw an image offscreen and paint that on but it still took the same amount of time since it needed to still draw each pixel to the offscreen image.
I was wondering what I need to do to make it faster. Would threads be the solution?
Thanks

Kurbz wrote:
iterations = getIterations(real, imaginary);  //method that computes color for each pixel
if (iterations == maxIterations)
     g.setColor(Color.BLACK);
else {
     red = (iterations % 32) * 7;
     green = (iterations % 16) * 14;
     blue = (iterations % 128) * 2;
     g.setColor(new Color(red,green,blue));
g.drawLine(x,y,x,y);
My experiments show using the WritableRaster of a BufferedImage to be about 3 times faster than using setColor and drawLine (ignore hackish code):
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
public class GraphicsTest1 {
   static volatile boolean isPainted = false;
   private static final Dimension dim = new Dimension(800, 800);
   public static void main(String[] args) {
      final JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
         .getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(
               dim.width, dim.height, BufferedImage.OPAQUE);
      final JPanel panel = new JPanel() {
         @Override
         protected void paintComponent(Graphics g) {
            if ( isPainted ) {
               g.drawImage(image, 0, 0, null);
            } else {
               super.paintComponent(g);
      final Thread t = new Thread(new Runnable() {
         @Override
         public void run() {
            WritableRaster raster = image.getRaster();
            Graphics2D gr = image.createGraphics();
            Random rnd = new Random();
            long nanos = System.nanoTime();
            for ( int x = 0; x < dim.width; x++ ) {
               for ( int y = 0; y < dim.height; y++ ) {
                  int r = rnd.nextInt(128)+128;
                  int g = rnd.nextInt(128)+128;
                  int b = rnd.nextInt(128)+128;
//                  setPixel(raster, x, y, r, g, b);
//                  setPixel(image, x, y, r, g, b);
                  setPixel(gr, x, y, r, g, b);
            System.out.printf("Seconds taken: %f%n", (System.nanoTime() - nanos) / 1000000000.0);
            gr.dispose();
            isPainted = true;
            panel.repaint();
      t.start();
      frame.setContentPane(panel);
      frame.setVisible(true);
      frame.setSize(dim.width, dim.height);
   private static void setPixel(WritableRaster raster, int x, int y, int r, int g, int b) {
      raster.setPixel(x, y, new int[] {r, g, b});
   private static void setPixel(BufferedImage image, int x, int y, int r, int g, int b) {
      image.setRGB(x, y, r << 16 | g << 8 | b );
   private static void setPixel(Graphics2D gr, int x, int y, int r, int g, int b) {
      gr.setColor(new Color(r, g, b));
      gr.drawLine(x, y, x, y);
}

Similar Messages

  • Help - Importing Large Images Fails

    Hi,
    I use Flash primarily for animation.  The project I'm working on currently is a hefty 1920 X 1080 square pixel file and currently weighs in at 187mb because of all the sounds and jpg images.  It's 2 minutes long.
    The problem occuring is new to me as I've never worked with projects this long or in this resolution.  Or with this much data (sound effects, jpgs, etc).
    The problem is this: I'm trying to import a high resolution photograph (3500x2500) onto the stage or even just in the library.  I'm using the photos to get an idea on where the final animation will be placed (photo backgrounds, flash animation, composited in After Effects, think Roger Rabbit).
    And it's been working until now.  I've imported, scaled, and animated a lot of jpgs, sounds, and photos without incident as well as drawn a lot of new frames using the brush tool.
    I'm near the end of the project, and of course, Flash craps out on me, either crashing (closing automatically) on me every time I try to import the 20th of about 25 hi-rez photos, or giving me some error saying the file I'm trying to import is corrupted.  And when I try to import other files it gives me the same problem.
    Here's the kicker though, when I open a new stage and close the project I'm working on and try to import the same files, I am able to import
    those supopsedly corrupt images.  My theory is that Flash cannot deal with projects like mine, with lots of hi-rez photos in the timeline (though only one hi-rez photo on the stage at any given time.  It might be a RAM memory problem since Flash is vector based.  I have 2gigs of DDR RAM on my computer and it's a 2GHz Athlon processor.
    I currently use Flash CS3 and Flash 5 and have experienced the same issues in both.
    My question to those who have encountered similar problems in the past is how do you get around this?  What's your work flow?
    Do you split the project up into smaller chunks so you can import onto the stage what you need to work on in that chunk so Flash doesn't crash?
    Do you use another program to composite and cross your fingers in the hopes the animation will line up with the imported background?
    This project requires animation synced to the sound, so syncing after animating is not an option.  Likewise, the animation has to appear in the right place on the screen, so importing photos to the stage is a must for placement issues.  And lastly, it has to be HD resolution, so the photos I use have to be hi-rez too, which means huge filesizes.
    Since it's not for the web, it's not an issue for me what the filesize is, but it seems to be for Flash and that's why it keeps crashing now that's I've pushed it to its limits.
    I'm curious if there are any solutions that will prevent it from crashing in the future or work-arounds that will allow me to avoid reaching Flash's limits as I finish laying in the photo bgs and begin animating.
    Ideas welcome.

    *bump*

  • Horizontal scrolling. Help with large images.

    Putting together a .pdf publication for iPad.
    I have content that fits a standard iPad format BUT I also have these very long timelines (170cm x 21 cm). These need to be displayed zoomed in -  with the reader swiping right to accessing the remainder of the content. So a horizontal scroll! Whenever I test it on the iPad it display the full image (so zoomed out and tiny). The other images are displaying fine.
    So how do I make sure I view them as I require?
    Thanks!

    I also need this feature, to view and mark up street plans that are long narrow landscape format pages with "match lines" at the left and right sides.  What I want is similar to Acrobat's existing "Enable Scrolling" -- but in the horizontal direction.  Planners need this for road and path plans.  Musicians and composers need this for viewing multi-page sheet music so they can browse the entire "timeline" of the piece.  And as the OP notes, schedule planners need this for reviewing timelines such as Gantt charts.
    Adobe, please add this feature.  I'll gladly pay for an upgrade (currently using Acrobat Pro XI Mac).

  • HELP! How do I link small thumbnail to larger image on same page?

    hello, everyone! I'm working in dreamweaver cs4 and am having no luck!
    see below - I'm trying to link the small thumbnails to the larger image on the left. in other words, when a thumbnail is chosen it's corresponding image would open on the left. I have tried mouse-over effects and image swap behaviors but still no luck. either the larger image replaces the thumbnail or a brand new window opens up with the larger image.
    I want all effects to stay on the same page. any help would be greatly appreciated!

    Hi There:
    Not sure how you have designed your page but here is a simple sample code on how you can do this with javascript and on mouseover event:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    div#left {
    display:none;
    </style>
    <script language="javascript" type="text/javascript">
    <!--
    function showImage(obj) { //v2.0
    //alert(obj);
    document.getElementById(obj).style.display='block';
    //  return eval(obj)
    function hideImage(obj) { //v2.0
    //alert(obj);
    document.getElementById(obj).style.display='none';
    //  return eval(obj)
    //-->
    </script>
    </head>
    <body>
    <div id="left" style="float:left;width:200px;"><img src="left.jpg" width="180" height="273" alt="large" /></div>
    <div id="right" style="float:right;width:200px;"><img src="thumbnail.jpg" alt="small" style="cursor:pointer;" width="57" height="228" onmouseover="showImage('left');" onmouseout="hideImage('left');"/></div>
    </body>
    </html>
    By default the bigger image is initally not there so I have added a display:none style in the head.
    The above code will show the bigger image on left when you do a mouseover on the smaller left thumbnail image. Vice-versa when you move out the mouse the image goes away (you may not need this part). So on each thumbnail image simlarly pass the id of the image you want to show via the javascript showImage function.
    Note: You can use onclick or other event per your preference.
    Regards,
    Vinay

  • Need to read/paint large images fast. Help!

    Hello Java community,
    I am having trouble writing a program which can read large image files from disk (~ 1-2 MB) and paint them to the screen while maintaining a frame rate of 15 or 20 fps. Right now I am doing this through a Producer/Consumer scheme. I have one thread which constantly creates ImageIcons (using the constructor which accepts a String file path), and places them on a blocking queue (production) with a maximum capacity of 5 or 10. I have a second thread which removes an image from the queue (consumption) and paints it to the JFrame every so many milliseconds to honor the frame rate.
    My problem is that this approach is not fast enough or smooth enough. With smaller images it works fine, but with larger images it cannot maintain a high frame rate. It also seems to consume more memory than it should. I am assuming that once I paint a new ImageIcon, the old one goes out of scope and is freed from memory by the Garbage Collector. However, even with a queue capacity of 5 or 10, I am getting out-of-memory exceptions. I plan on trying the flush() method of the Image class to see if that helps to recover resources. After searching around a bit, I see that there are many different ways to read/load an image, but giving a local path to an ImageIcon and letting it load the image seems to be a safe way to go, especially because in the documentation for ImageIcon, it says that it pre-loads the image using Media Tracker.
    Any help, ideas, or links would be appreciated!
    Thanks,
    Elliot

    Thanks for another insightful response.
    I've played a bit more, so let me update you. I am preloading images, the blocking queue (FIFO) is full when the animation begins. Right now, the queue capacity is 10, but for smaller images it can be closer to 40 or 50. The image reader queue reads images and places them in this queue. Oddly, the problem does not seem to be that the reader thread can't keep up. I added a print statement which displays the size of the queue before each removal and it remains very close to the capacity, at least for the my test images which are only 400 x 400, approximately 100 KB each.
    I've tried animating the images in two distinct ways. My first approach, as I mentioned in the original question, was to animate the images using purely swing components and no manual painting of any kind. This is always nice because it frames the image perfectly and the code is minimal. To accomplish this I simply had the image reader thread pass in the image path to the constructor of ImageIcon and put the resulting ImageIcon in the queue. The animator thread had a simple swing timer which fired an ActionEvent every so-many milliseconds (in the event dispatch thread). In the actionPerformed method I simply wrote a few lines to remove the head of the queue and I used the JLabel setIcon(ImageIcon) to update the display. The code for this was very nice, however the animation was choppy (not flickering).
    In my second approach, which was a bit longer, I created a class called AnimationPanel which extended JPanel and implemented Runnable. I simply overrode paintComponent and inside I painted a member Image which was set in the thread loop. Rather than storing ImageIcons, the queue stored Images. The reader thread used ImageIO.read(...) to generate an Image. I used simple logic in the thread loop to monitor the fps and to fire repaints. This approach suffered from the same problem as the one above. The animation was choppy.
    I found the following things to be true:
    - the reader can keep up with the animator
    - if I run the image reader and perform a basic polygon animation, both of my approaches animate smoothly at high frame rates. In other words, it's not the work (disk reads) being done by the reader that is causing the lag
    - I believe the slowness can be attributed to the following calls: label.setIcon(imageIcon) or g.drawImage(image, 0, 0, this). This leads me to believe that the images are not fully processed as they are being placed on the queue. Perhaps Java is waiting until they are being used to fully read/process the images.
    - I need to find a way to process the images fully before trying to paint them, but the I felt that my approaches above were doing that. I considered have the reader frame actually generate a JLabel or some object that can be displayed without additional processing.
    - your idea about AWT components is a good one and I plan on trying that.
    Elliot

  • 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!

  • How to load a large image for display on the Palm PDA

    Hello:
    I have a large image I would like to display on LV for Palm PDA. The documentation states there should be a 64K chunk limitation for VIs to compile on the Palm. Therefore, I decided to break this image up into 2D arrays of less than 64K per subVI. My 3.2 Meg image therefore has about 224 2D array subVIs. My motivation is to somehow use the build array function (with concatenate inputs) to reconstruct the image at runtime. I can compile each 2D array subVI as a test, but my attempt to reassemble and compile is futile. When I try to use the build array with only 8 of these subVIs in a top level VI the compiler complains its still too big of a VI. Using get info, memory for this top level states total ~2
    3K of memory usage.
    So can someone help me with this problem. Is there another way to load this size of an image into memory so I can display it on a picture control?
    BTW, this can build on LV for PocketPC.
    Thank you
    Robert

    Hi Robert,
    You are correct in that one of the limitations of the Palm OS is that files cannot be larger than 64 KB in size (as stated on page 5-3 of the LabVIEW PDA Module User Manual). The suggested workaround is indeed to have a top-level PDA VI that calls subVIs, and this top-level VI can then have a total file size larger than 64 KB.
    My suspicion is that with the picture control on the Palm OS, even if you are breaking up the image into smaller subVIs, the process of building the array to reassemble the picture is still forcing the Palm to allocate memory for each of those 2D array subVIs to place on the top-level VI's picture control
    and thus causing the Palm to complain about not having enough memory. The LabVIEW PDA User Manual also states that "There is a total limit of 64 KB on all front panel array data". Thus, when you are trying to use the build array on the top-level VI, the 64 KB limit on front panel array data is still being exceeded -- even with only 8 of these subVIs.
    The following KnowledgeBase article KB 38EJRHFQ: How Do I Put a Picture or Image on My LabVIEW PDA for Palm Front Panel? states that as a workaround, you can shrink the size of your image by using 4-bit or 1-bit data instead of the standard 8-bit pixmap representation.
    This is really just a limitation of the Palm OS and the fact that there is simply no way of displaying that much front panel information for your picture. Either way, you would need to build up the array of pixels for your bitmap, and for a 3.2 MB image, I don
    't believe there is any way for the Palm OS PDA to display the image in its entire at once.
    Sorry about that...
    Kileen C.
    National Instruments

  • Unable to create large image file in iphoto

    I make a lot of panoramic images by stitching together overlapping images with hugin in TIFF format, then edit them in iphoto and use it to export them in jpeg format for greater versitality of use. So far I haven't had any trouble, even with large images as big as ~25,000x2000 pixels and ~90MB file size.
    However, I have come across a problem recently trying to export an edited version of a particularly large one - 38,062x1799 136MB file size. I can export an unedited version to jpeg without trouble, but when I tried to export an edited version it gave me an error saying it couldn't create the file. I looked around here for solutions and found the suggestion to check the file size in finder, it was zero. After experimenting I've found that the file size goes to zero as soon as any changes are made to the file, the edited image can still be viewed in iphoto, but does not display if you try to zoom in. I have tried making the TIFF file again with hugin to see if it is a problem with the file, but I also experience the same problem with the newly made file.
    I am working on a Macbook air (1.7 GHz Intel Core i5, 4 GB 1333 MHz DDR3 Memory, Intel HD Graphics 3000 384 MB, Version 10.7.5 OS X) in iphoto '11 version 9.2.2 (629.40). Any suggestions for getting round this issue?

    I thought of something that might help with working out what's going on.
    After I make any edits to the image, if I move on to the info tab the image initially goes a bit blurry as it often does with large images, but instead of coming up as a clear image after a few seconds like normal, I get the image I've attached here and the file size changes to zero. To be able to see the thumbnail of the edited image I need to come back out to the library again, but the file size is still zero. If I revert to original the file size is restored.

  • Button to b clicked and large image shown on the stage(link to swf file here)

    I have a button when clicked is supposed to show a larger image of the button/ I am new to the code and think if I could see and example it would help. This is a school project. I am failing as of now.
    how do I upload my files to here so I can show   http://threadcontent.next.ecollege.com/(NEXT(54b34a37e8))/Main/CourseMode/Thread/DownloadA ttachment.ed?virtualFileId=961613945&GoldenTicketParams=_u=8538800;_dt=634657009144447173; virtualFileIDs=956864518,956864621,956864990,960296914,960355361,960465721,960465764,96037 9092,961379343,960908613,961013978,961014291,961613945,961035853,961618981,961042519,96144 4490,961569920,961629398,961629452;&GoldenTicketSignature=35-AA-34-CE-10-A6-FD-4F-D1-DD-73 -4C-A9-EF-8D-9D-63-E5-87-88-FB-D4-4D-15-06-BB-82-8A-9E-F2-36-DC
    I believe this is the download link to the swf I have you can see the buttons click and sound and over and when pressed they are supposed to show the larger image of the buttons original image that you see before you hover

    stop();
    trail_btn.addEventListener(MouseEvent.CLICK,
    trail);
    function trail(event:MouseEvent):void
        gotoAndStop(10);
    and the link I gave is the download link from my class at AI Online its perfectly fine

  • Trying to link a thumbnail in one frame to a larger image in another frame GOLIVE 9...

    Hi.
    I am using Adobe Golive 9.
    I found a tutorial on the internet that allows you to create an image gallery with clickable thumbnails
    http://www.tutorialhero.com/click-48179-create_an_image_gallery_with_clickable_thumbnails. php
    However, the tutorial is designed for a page without frames.
    I want to be able to do this using frames.
    I want to link a thumbnail on a page in one frame to a larger image on another page, so that when your mouse is over the thumbnail,
    the larger version appears in the other frame.
    This is what my frames look like so you get an idea of what I'm trying to do
    And here is a picture of the thumbnail in the lower frame and the larger image in the frame above it.
    Could someone please give me STEP BY STEP instructions on how to do this?  I'm new to Golive, using version GOLIVE 9, and I know this can be accomplished using "Set Image URL"  but have no idea how to do it.
    Thank you for your help all.
    Chris.

    A link in one frame is designed to call another page into some other frame, not an image. You can't use SetImageUrl across different pages. You'd probably have to put each of your large images on a page, and call each page each time. I'm not sure why you're so set on using frames, they have many disadvantages.

  • Preview of pages containing large images ( 600MB)

    Hello,
    I use the CS3-Server with the Java API, I have to export a pagepreview from a certain page of an indd-document as JPEG. The page that I have to export contains images each with a size greater than 600 MB. At the moment I call the doExport-method of the document-object. My JPEGExportPreferences are all set to lowresolution (72 dpi) and low JPEGQuality (kJPEGOptionsQualityLow).
    But the JPEG-Export always lasts over 20 seconds which is too long.
    The document must contain these images. This cannot be changed.
    Now I search different way to get a pagepreview. When Indesign saves a document it saves previews as well, is it possible to use these previews? Or does anybody know a way to tell Indesign to use its internal preview instead of the large image to generate the pagepreview?
    I already tried to unlink the image but the unlink-process lasts even longer than the preview generation process itself :-), even the relink to an non-existant image did not work.
    I don´t know how to handle this...Does anybody run into this problem before and perhaps can help me, PLEASE?
    Thank you!
    Gregor

    The short answer is not yet - although the expectation of 64-bit Aperture is that it HAS to be out SOON. I shoot a lot of film in medium and large format and the scans are 16bit 4000dpi some of my files exceed 2gigs and still use Aperture to organize them along with references to my negative files but Aperture will not deal with 1G files right now no matter how much memory you jamb in your machine it is pure 32bit and cannot manage multiple 32bit address spaces soooo....
    4G address space - OS X and shared 32bit reserved address space - program/text space - the amount of memory Aperture uses for other things - etc = a lot less than 4G actually a lot less than 2G.
    Hope that makes a long story short. Just thank heavens that OS X did not reserve 2G in address space like some older unicies.
    RB

  • How to get larger images in albums?

    I just realized that when you click on a thumbnail in one of my albums, the larger image is actually smaller than the original photo! All the photos I've put into my web albums have been shrunk to fit into the album display area. For instance, a photo that normally displays about 7 inches high when I view in Preview, comes out about 4.5 inches tall when displayed in my web album.
    How can I get it to display photos at actual size?

    Ray Dunakin wrote:
    I tried turning off "optimize images", but they still were showing up at the reduced size.
    providing a url to your site so people could have a look at what's going on may help...
    What I'd really like is a way to designated specific images to display at a larger size -- most don't need to be very large, but some do.
    I think that's not possible in iWeb PhotoPages... As you choose one format for all. However to get larger images in albums click on a photo and a window will popup called "Photo grid". You can increase the size of the images displaying by reducing the spacing and/or decreasing the number of columns.
    Regards,
    Cédric

  • Gallery - Link from large image

    Having started with the spry image gallery, I am having
    trouble adding a link using the large image. Anyone know how to
    extract the image ID and make it a link for the large image to go
    to a detail page.

    Hi Henry,
    Here's a way how to do that:
    1. Add a js function that sets a new url for the image
    onclick everytime the source of the image changes. Add it in the
    head of the page (right after the XMLDataSets declarations):
    // this function is called every time the source for the main
    image is changed
    function SetMainImageLink(curRow) {
    var img = document.getElementById("mainImage");
    if (!img)
    return;
    var path = 'product_detail.cfm?ID=' + curRow["@path"];
    img.onclick = function() {
    window.location.href=path;
    2. open gallery.js file and locate this function: "function
    ShowCurrentImage()"
    3. call SetMainImageLink from within ShowCurrentImage. Here's
    the full source for the modified function ShowCurrentImage()):
    function ShowCurrentImage()
    var curRow = dsPhotos.getCurrentRow();
    SetMainImageLink(curRow);
    SetMainImage("galleries/" +
    dsGalleries.getCurrentRow()["@base"] + "images/" + curRow["@path"],
    curRow["@width"], curRow["@height"], "tn" + curRow["ds_RowID"]);
    4. (optional) you can edit the img tag and add a style on it,
    so it display a hand cursor when you mouse over it.
    <img id="mainImage" alt="main image"
    style="cursor: hand; cursor: pointer;"/>
    Hope this helps you,
    best regards,
    Dragos

  • Roll over to view larger image, click to select

    Which combined server behaviors or technologies would allow
    me to create a dynamic image gallery of thumbnails that when you
    roll over any thumbnail image (images are populated via repeat
    region recordset behavior), you can view a larger image. Selecting
    a thumbnail would select the larger image version.
    I do not need to know how to create the thumbnail images
    (this would be achieved via aspjpeg with a repeat region applied to
    it) but rather how to make it work as explained.
    check out
    https://www.schooloutfitters.com/catalog/product_info/pfam_id/PFAM898/products_id/PRO987
    for an example.

    OK so I'm almost there! A little more help if it's not too much trouble.
    I've used the "mouse-over to enlarge" example and it seems to be working.
    The images sit together top left (ie. the larger image appears over the top of the smaller image and both top left corners of the images sit in the same x and y position - it appears to grow to the right and down!). Can I change this so that the images sit in the same position bottom right and the image grows bigger, up and right?
    Alternatively if it's easier I could do "mouse-over and click", but I need the click to open my image in a new window, sized to the image (so I can still see the main page in the original browser window).
    Thanks again
    Lopoc

  • Displaying Large Images and Out of Memory Error

    hi,
    I am relatively new to JAVA and I have been trying to display a large jpeg in a scrollpane. The image is about 30 mb in size and is very long. When compressed the image is very small (1mb) but when uncompressed it increases in size due to the black background. I have been looking all over the place to find a method to display such a large image. I read a little bit about the JAI and its tile features but I am not really familiar with it. Also the image has to be displayed in an applet. the whole mess has to do with the JAVA VM memory restrictions as it does not have enough memory to process the image. Is there a way to uncompress a part of the JPEG and display it or assign addittional memory to JAVA. I will really appreciate any help on this topic.
    thanks

    Hiya.
    I can't say I know how to save Java from large images, but you can up the memory allocated to the JVM:
    java -Xmx120M ...
    will give 120M to the JVM (max). There is an -Xms also which gives the initial allowed space.
    Regards.
    Paulj.

Maybe you are looking for