Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] SWT getImageData().type always -1

Carolyn MacLeod wrote:


If you care about the type of file an Image was read from, you need to read it into an ImageData first, and then create your Image from that. (as opposed to reading directly from file into an Image). Image class does not retain information about where the Image originally came from. Only ImageData class does that.

        ImageData data = new ImageData("C:\\graphic.bmp");
        Image image = new Image(device, data);
        // At this point, data.type will be SWT.IMAGE_BMP
        // and image.getImageData().type will be -1 (SWT.IMAGE_UNDEFINED)

See org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer (available in the eclipse examples zip on the eclipse download page) for an example that reads from file into an ImageData and then gets the Image from the ImageData.

Carolyn

One more note on the subject of imagedata....I have found that ImageData returns a bit depth of 8 for any image with less than this bit depth. The correct number of colors in the pallette is given by the length of the colors array in pallette. This bug/problem can cause some serious issues when attempting to convert index - direct color pallettes. I have not had time to search the bug database but thought I would make you aware of it since you are working with image data.

Ez


Back to the top