Memory and image coloring

I want to keep a lot of images in the memory, so I use an array of images. The images are simple drawings and use few very few colors, thus take few space. I think they take 200 ko all together. However, once in a Image object, I suspect java to use billions of color because an Out of memory exception is declared. I can't believe 200 ko fill the memory up!! I know I can use a BufferedImage but I haven't found a way to load a BufferedImage from a file... help!

Here's a demo: by writing the image in PNG format, I can directly read it as a BufferedImage that
has an IndexColorModel.
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class IndexedExample {
    public static void main(String[] args) throws IOException {
        BufferedImage im1 = getOriginalImage();
        BufferedImage im2 = toIndexedType(im1);
        File file = new File("temp.png");
        saveImage(im2, file);
        BufferedImage im3 = loadImage(file);
        display(im1, im2, im3);
    static BufferedImage getOriginalImage() throws IOException {
        String url = "http://today.java.net/jag/bio/JagHeadshot-small.jpg";
        return ImageIO.read(new URL(url));
    static BufferedImage toIndexedType(BufferedImage im) {
        BufferedImage indexed = new BufferedImage(im.getWidth(), im.getHeight(),
            BufferedImage.TYPE_BYTE_INDEXED);
        Graphics2D g = indexed.createGraphics();
        g.drawRenderedImage(im, null);
        g.dispose();
        return indexed;
    static void display(BufferedImage im1, BufferedImage im2, BufferedImage im3) {
        JPanel cp = new JPanel(new GridLayout(1,0));
        addImage(cp, im1, "original");
        addImage(cp, im2, "indexed");
        addImage(cp, im3, "from file");
        JFrame f = new JFrame("IndexedExample");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(cp);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    static void addImage(JPanel cp, BufferedImage im, String title) {
        JLabel label = new JLabel(new ImageIcon(im));
        label.setBorder(BorderFactory.createTitledBorder(title));
        cp.add(label);
    static void saveImage(BufferedImage im, File file) throws IOException {
        String filename = file.getName();
        int dotIndex = filename.lastIndexOf('.');
        if (dotIndex == -1)
            throw new IOException("No file extension");
        ImageIO.write(im, filename.substring(dotIndex+1), file);
    static BufferedImage loadImage(File file) throws IOException {
        BufferedImage im = ImageIO.read(file);
        if (!(im.getColorModel() instanceof IndexColorModel))
            System.out.println("file image type is not ICM!");
        return im;
}

Similar Messages

  • When inserting a .pdf of a document with a standard white paper color the test and images show up, but the white background is transparent. How do you also make the white paper color show up?

    When inserting a .pdf of a document into a Keynote template with a standard white paper color the text and images show up, but the white background is transparent. How do you also make the white paper color show up?

    Use the color fill option - select the inserted .pdf and assign a fill color of white to it using the Color Fill Menu on the Toolbar or the Color Picker Palette.
    Good Luck.

  • I can select a rating and a color label for my images, but I can not sort by rating and color label.

    I can select a rating and a color label for my images, but I can not sort by rating and color label. when I click on the filter drop down, color label is not one of the options.  how do I get both ratings and color lables as an option to sort with.

    You can Filter (not sort) on both color label and rating if you want, open the Filter Bar with the backslash key, then click on Attribute, and then select the stars and color label of interest. If you really meant "sort" and not filter, then you can't do this in Lightroom.

  • Prob: Creating Image in memory and printing "hello" on it, then saving it.

    How can i create an Image instance in memory and then do a drawString "Hello" on it, then save it to disk.
    I'm not loading the image, i'm not displaying it onscreen.... It's all in memory. So i can't to createImage, like in an applet... or Window.createImage...
    I need to create a new image with a width and height, and then save that to disk. I have the save part, how about the create part :(
    Thanks a million

    import java.awt.image.BufferedImage;
    import java.awt.Graphics2D;
    BufferedImage img=new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D gfx=img.createGraphics();
    gfx.drawString("Hello World",x,y);- Marcus

  • Blinking images and messageBox colors

    I am looking for the most efficient way to create an image (such as a .gif or .jpg) that blinks for a specified amount of time. I tried to do something with the setTimeOut method, but Adobe doesn't seem to like it.
    I would also like to change the color of messageBoxes based on certain events, but am not sure how to reference the color value of the box.
    Any thoughts or suggestions?
    Thank you
    Brian

    I have not seen either one of your request done before. The only way I can think of to have a blinking image is to create an animated gif.....but I do not think that the gif will animate in PDF.
    The messageBox is created by a call to the Javascript engine and the color of the box is not exposed as a changeable parameter.

  • On my screen the image is clear and the colors are right, However when I print to either my epson of HP the image color is off.

    On my Mac screen my photo image is clear and the color are right, however when I print to either my epson 2200 or my HP printer bother the colors are off and the image is not as clear as on the screen.

    Hi there,
    This article should cover the issue you are experiencing. Give the steps outlined a shot and let us know if it helps.
    Best of Luck!
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • Problems viewing the files and images on a memory ...

    I have a series of folders and images in a memory card that I used to use with my 6300. However, since moving to the 5800, I can't see the folders or images that I stored on the card and my 5800 also mis reports the memory status!? Can anybody help??
    Do I need to download the images and reformat the memory card due to an incompatibility issue? But surely the 5800 is compatible with the 6300!?? 

    The 5800 and 6300 use totally different operating systems so there's no reason why the data layout and directory structure used by one should also be used by the other.
    Was this post helpful? If so, please click on the white "Kudos!" star below. Thank you!

  • My Mac Book Pro has just had a new memory and solid state drive installed. After the installation, the Lightroom tools all became grey. There is no longer any color on the screen other than my picture. Even the color sliders are grey.  Can you please help

    My MacBook Pro just had a new memory and solid state drive installed. Since the installation, the Lightroom tools are now all grey. Even the color sliders are grey. Please help!

    My guess is that your operating system got updated to Mavericks and that you are running an old version of Lightroom:
    Sliders are white, look different | Mac OS X 10.9 Mavericks
    Be aware of a Lightroom bug with color management in mavericks that makes shadows too deep in the Develop module: Jao's photo blog: Serious color management bug in Mac OS 10.9 "Mavericks" and Jao's photo blog: Further quantification of the Mavericks color management problem.

  • Colors and images on itunes U site not displaying correctly.

    After the issues of not being able to login this weekend our site has dropped much of it's theming, including colors and images. The page/course thumbnails still show as well as the background image, but all the other areas look like they are missing the background images. Is anyone else having the same issues with their site. This is the original "private" site, not the new PSM version.
    Thanks,
    Kyle

    Yes, my store and another institution as well - we mentioned the new problem here:
    https://discussions.apple.com/thread/3142618?tstart=0

  • Photoshop Help | Adjusting image color and tone

    This question was posted in response to the following article: http://helpx.adobe.com/photoshop/using/adjusting-image-color-tone.html

    Andy Anderson goes through hue and saturation settings in this Photoshop CS6 tutorial video: http://infiniteskills.com/blog/2012/08/adobe-photoshop-cs6-tutorial-hue-saturation/

  • Mail- Images color and contrast?

    Why is it that Apple forgot color management in the Mail program. I am a photographer and I have my images approved by the client via email. Shoot to CaptureOne Pro then Process raw to tiff open in Photoshop and the color and contrast match convert to Jpeg and attach to email and it looks muddy in the email. Clients respond to me image looks flat what is wrong with it. All my clients use Adobe 1998 color space. I have to tell them to open it in photoshop and they always say "Oh thats better"
    Am I missing the option to use Adobe 1998 instead of sRGB in the mail program? Some of my clients use the Jpegs for placement in their layouts so I need to keep the Adobe 1998 color space and not convert it to sRGB just so it will look right in one of a series of programs.

    Why is it that Apple forgot color management in the Mail program.
    I assume because images are sent as attachments which appear inline or viewed in place within the body of the message by default with the Mail.app which is not the same with all email clients.
    If you send such attachments to a recipient using Windows Outlook or Outlook Express, the attachments will appear as attached files only which must be opened separately in order to view.
    I don't believe the majority of people that use the Mail.app need it to be used in such a fashion and I don't believe any email client has anywhere near Photoshop's color management capabilities since this is not what an email client is primarily designed for.

  • My iphone has a problem, it simply does not work, the screen is all black with a few colorful scribbles and images blend, I used it only took 6 days and returned to service when operated only 7 more days and it happened again the same thing, what do I do?

    My iphone has a problem, it simply does not work, the screen is all black with a few colorful scribbles and images blend, I used it only took 6 days and returned to service when operated only 7 more days and it happened again the same thing, what do I do?

    Reset the PRAM
    Reinstall the operating system from the dvd (you will not loose your data)

  • Pavilion Sleekbook x64 has grainy and distorted images, color is mostly red, anyway to fix this

    Intel(R) HD Graphics 400
    HP Pavilion Sleekbook 14: images are grainy, distorted and mostly red.  Can anyone help.

    Hi @ramses66 ,
    Thank you for visiting the HP Support Forums and Welcome. I have read about your HP Pavilion 14 Sleekbook and images being distorted or red. Try connecting the notebook to an external monitor with VGA or HDMI. Here is a document to show you how to do that if needed.
    If it is you are having issues with a graphics card.  If it doesn't happen on an external monitor we dealing with a hardware issue with the display.
    Here is a document on Resolving Video and Graphics Issue.
    Hope this helps.
    Thanks.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom to say “Thanks” for helping!

  • I have an iMac 5.1 with Mac OSX 10.6.8 and 2 GB memory and an L2 cache of 4 GB.   lately I have been receiving error messages of " start up disk almost full; please delete files." is the start up disk the same thing as the hard drive?

    I have an iMac 5.1 with Mac OSX 10.6.8 and 2 GB memory and an L2 cache of 4 GB.   lately I have been receiving error messages of " start up disk almost full; please delete files." is the start up disk the same thing as the hard drive?  I opened the hard drive and from the column on the left of the menu I've selected "search for" and under that " all images" then "all documents"  I've deleted a few files from each. Are documents and images that I have deleted from here also deleted from the folders on my desktop?

    You should never, EVER let a conputer hard drive get completely full, EVER!
    With Macs and OS X, you shouldn't let the hard drive get below 15 GBs or less of free data space.
    If it does, it's time for some hard drive housecleaning.
    Follow some of my tips for cleaning out, deleting and archiving data from your Mac's internal hard drive.
    Have you emptied your iMac's Trash icon in the Dock?
    If you use iPhoto, iPhoto has its own trash that needs to be emptied, also.
    If you store images in other locations other than iPhoto, then you will have to weed through these to determine what to archive and what to delete.
    If you use Apple Mail app, Apple Mail also has its own trash area that needs to be emptied, too!
    Delete any old or no longer needed emails and/or archive to disc, flash drives or external hard drive, older emails you want to save.
    Delete any other mail in your Junk folders. Also, look through your Sent Mail to see if there is anything that can be deleted.
    Other things you can do to gain space.
    Once you have around 15 GBs regained, do a search, download and install OmniDisk Sweeper.
    This app will help you locate files that you can move/archive and/or delete from your system.
    STAY AWAY FROM DELETING ANY FILES FROM OS X SYSTEM FOLDER!
    Look through your Documents folder and delete any type of old useless type files like "Read Me" type files.
    Again, archive to disc, flash drives, ext. hard drives or delete any old documents you no longer use or immediately need.
    Look in your Applications folder, if you have applications you haven't used in a long time, if the app doesn't have a dedicated uninstaller, then you can simply drag it into the OS X Trash icon. IF the application has an uninstaller app, then use it to completely delete the app from your Mac.
    Download an app called OnyX for your version of OS X.
    When you install and launch it, let it do its initial automatic tests, then go to the cleaning and maintenance tabs and run the maintenance tabs that let OnyX clean out all web browser cache files, web browser histories, system cache files, delete old error log files.
    Typically, iTunes and iPhoto libraries are the biggest users of HD space.
    move these files/data off of your internal drive to the external hard drive and deleted off of the internal hard drive.
    If you have any other large folders of personal data or projects, these should be archived or moved, also, to the optical discs, flash drives or external hard drive and then either archived to disc and/or deleted off your internal hard drive.
    Good Luck!

  • Weird and unwanted color gradient after Photomerge

    Hi all,
    I got an annoying problem with a weird color gradient that appears where it shouldn't. My context is, that I'm producing underwater photomosaics. I use Photomerge for merging, which works great for the often uniform seabed sediment images.
    [merge1.jpg]
    The example is 65 images, btw. After placing the images manually within Photomerge, all looks great and ready for a perfect result after rendering (see above). However, when doing so, the final merge from within Photomerge (by clicking the OK button) creates perfect smooth blending, but a weird color gradient crossing the whole mosaic. this might originate in the fact, that the individual images also are not perfect, due to the uneven lighting situation underwater. In case all images are a bit reddish at the top and yellowish at the bottom, the final gradient over the full mosaic shows that as well. So to me it looks as if Photoshop just tries to be too smart and thinks, reapplying that pattern to the whole would be a great thing to do, which it isn't of course.
    [merge2.jpg]
    I discussed this "bug" with (indeed very helpfull) Adobe staff and they recommended, to create the merge with the "Blend Images Together" option in the "Load" dialog unchecked. This creates a mult-layer document after rendering, with the images being placed properly but not blended.
    [merge3.jpg]
    From here on, Adobe staff  recommended, I shall use the "Auto Blend Layers" function (File menu), but the result is identical as image 2. Ok, then, they recommended, to uncheck "Seemless Tones and Colors" in the "Auto Blend Layers" dialog. Indeed, this gets rid of the gradient, ...
    [merge4.jpg]
    ... but shows very hard edges of the images, which get very prominent after optimizing levels:
    [merge5.jpg]
    Was that understandable? Would anyone have experienced (and solved) the same issue? Or would anyone have an idea, how this could be handled in a way, that my resulting mosaic looks as perfect with respect to the original colors as in the initial merge window before rendering it (image 1)? Maybe it's a specific Color Setting (Edit menu)? I tried a lot so far but nothing helped and I might not have tried the right thing.
    The problem appears, btw, in CS3 to CS6!
    Any help appreciated, more information on request! Many thanks,
    g

    H there,
    @TLL: you're right with what you said about the subjective element. Getting spoiled is easy, but staying ambitious is good as well. I do these mosaics since 2003, when Photomerge was part of Elements only. Then, in the first years with CS and CS2, I never had this bug with the color gradient being applied to the final merge. This started with, I guess, CS3 and I think it's due to enhancements Adobe made to the programm (making it more "intelligent"). Unfortunately, sometimes enhancements have dark sides and cause unexpected issues elsewhere. And since we are a minority (making large merges), these do not get fixed, since the majority, stitching what, 20 image panoramas of their home and garden do not suffer. Their images have strong contours and contrasts and the issue gets effective only on uniform images like underwater sediment or, in your case, landscapes shot from above. Going back to CS or CS2 is no option, since only the newer versions give me the processing power I need, also is the blending much smoother.
    I played around with gradient masks but I haven't got the right touch yet. Even if I get rid of the color differences, there will always be a brightness gradient, since borders of the images are always darker. And then, the weird gradient is a bright / dark one, not a red / yellow one. Not much better. Also, each batch job has to work for thousands of images, so has to be a compromise. I just cannot spend more than a day for a 1000 image mosaic, or a week for 6000 images, time is money on a ship (and elsewhere).
    I just think the solution would be, splitting the "Seemless tones and colors" function up into "Seemless Blending" (doing soft blending but not changing the colors) and "Seemless Color Transitions" (just dealing with the colors). And making both optional by check boxes...
    So far,
    g

Maybe you are looking for

  • How do you import music onto ITUNES if you have two IPODS

    Question: I have two IPODS. I can't seem to figure out how to import all the music on my old IPOD onto ITUNES so I can put new music in my library as well as m new IPOD. Can you please help! Also, when I plug in my old IPOD it says it is in WIndows f

  • Itunes 7  downloading probs & authorization probs

    I wish I'd checked this forum before updating! I am getting error -50 on purchased music downloads and since I changed my log in password I keep getting the 'not autorised' message on every track I try to play despite authorising the computer and get

  • Camera raw adjustments not showing in prints

    I received a call from a technician with a professional processor about an issue I am having with prints that are much darker than what I see on my calibrated screen. The technician was wondering why I would send files that looked exactly like the or

  • BOM Prices for production...

    Hi Experts, My client activated the ML, They are following Actual costing...no Standard cost estimation... Now the reqirement is ..for one product they are having the multiple BOMs(With different combination of Raw materials), at the time of producti

  • HT4972 I need to updated my iPad to iOS 5 but don't know how please help?

    How do I update my iPad to iOS 5 or better please I'm so lost I need help thanks