Make your own free website on Tripod.com

Get the RGB value of a Pixel
ericlin@ms1.hinet


download getrgb.zip

Flash is considered as a tool for vector animation. It is born because vector data has the benifit of small in size than bitmap and the smooth outline even zoomed. Although it supports "bitmap", it does not intend to handle or manipulate pixel data.

Personally, I would favor java at present time. Java give more support for pixel manipulation. Java supports powerful API filter function to distort the images.

So, what if we need to read RGB data of perticular pixel in our Flash movie ? No way, by Flash itself. Of-course, we can create RGB data about that bitmap and supply this data to our movie then our movie picks the data. It has nothing to do with the bitmap in the swf. It just reads the array data that we created outside the Flash.

There are many ways to fetch the rgb value of each pixel in a bitmap.

Here is an example by JAVA.

Never mind, if you dont know java. Skip it. I think, php, perl or C should have similar API to do this.


The code use the ImageIO Class.

BufferedImage src=ImageIO.read(new File("science.jpg"));
int w=src.getWidth();
int h=src.getHeight();
for(int k=0;k<h;k++){
    for(int j=0;j<w;j++){
            int rgbValue=src.getRGB(j,k)+0xFFFFFF+1;
            //dump to screen or text file if we need
    }
}

After we get the rgb data, we can supply it to Flash by #include or make it swf and load it in;

The complete java code that did the job is included in the zip file above. Filenames are hardcoded.


What effect can we create by these pixel RGB data ? Well, I think there is potential.

However, that is not without pitfalls:

In Java, we can use setRGB to modify the rgb value of pixels and plot that bufferred image to screen to change the appearance of the bitmap. Flash does not support this. So, the rgb data is only for peek;

The rgb data is much larger than the compact bitmap binary itself. The loading work is more than double. Not very economic. This swf is 45 KB, if I strip off the rgb data array, it is 12 KB only.