Question
URGENT: setPixel and bitmaps
Hi,
We have an application that uses a colour picker to dynamically alter the colour of products. Will use a greyscale image as a base, which then has its greys changed to colours using a base colour. Or this is what we want any way. The problem I was having was I can not seem to load the gif image into the flash movie. And I am not sure I am using the set pixel function correctly. Btw , does set pixel take a 255255255 or FFFFFF value. I am not sure how to get the colours converted to hex from rgb in action script I saw a (r << ?) example some where. Is it possible to retain transparency in a gif using setpixel.
I have a gif image called kittens.gif, and a
import flash.display.BitmapData;
var Red = 0;
var Green = 102;
var Blue = 204;
var i = 0;
var linkageId:String = "Kittens"
var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);
this.kittensmovie.attachBitmap(myBitmapData, this.getNextHighestDepth());
for (i=0; i<100; i++)
{
var j = 0;
for (j=0; j<=100; j++)
{
pixel = myBitmapData.getPixel(i, j)
pixel = pixel/10000;
pixel = pixel-155;
Red = Red+pixel;
Green = Green+pixel;
Blue = Blue+pixel;
if (Red>255) {
Red = 255;
}
if (Green>255) {
Green = 255;
}
if (Blue>255) {
Blue = 255;
}
if (Blue<0) {
Blue = 0;
}
if (Red<0) {
Red = 0;
}
if (Green<0) {
Green = 0;
}
Red = Red*10000;
Green = Green*100;
pixelcolor = Red+Green+Blue;
myBitmapData.setPixel(i, j, pixelcolor)
}
}
We have an application that uses a colour picker to dynamically alter the colour of products. Will use a greyscale image as a base, which then has its greys changed to colours using a base colour. Or this is what we want any way. The problem I was having was I can not seem to load the gif image into the flash movie. And I am not sure I am using the set pixel function correctly. Btw , does set pixel take a 255255255 or FFFFFF value. I am not sure how to get the colours converted to hex from rgb in action script I saw a (r << ?) example some where. Is it possible to retain transparency in a gif using setpixel.
I have a gif image called kittens.gif, and a
import flash.display.BitmapData;
var Red = 0;
var Green = 102;
var Blue = 204;
var i = 0;
var linkageId:String = "Kittens"
var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);
this.kittensmovie.attachBitmap(myBitmapData, this.getNextHighestDepth());
for (i=0; i<100; i++)
{
var j = 0;
for (j=0; j<=100; j++)
{
pixel = myBitmapData.getPixel(i, j)
pixel = pixel/10000;
pixel = pixel-155;
Red = Red+pixel;
Green = Green+pixel;
Blue = Blue+pixel;
if (Red>255) {
Red = 255;
}
if (Green>255) {
Green = 255;
}
if (Blue>255) {
Blue = 255;
}
if (Blue<0) {
Blue = 0;
}
if (Red<0) {
Red = 0;
}
if (Green<0) {
Green = 0;
}
Red = Red*10000;
Green = Green*100;
pixelcolor = Red+Green+Blue;
myBitmapData.setPixel(i, j, pixelcolor)
}
}
