PDA

View Full Version : Photo to Sprite



cairnswm
31-03-2004, 07:46 PM
A while ago I asked a question about using Digital Photos as images in a game. I finally got the chance to try it out (preparing for the Ludum Dare contest :))

I first took a photo at lowest Resolution (1MegaPixel).

I then trimmed this down to a 64x64 real color image (name.bmp).

I then converted this image to a Monochrome bitmap (namemono.bmp). I then resave over mono as a 16 color bitmap - change the outside color (white in my case) to magenta - my normal transparency color.

I then created a small application. I created a form with 3 TImage components and a button. In Image1 I loaded name.bmp, in Image2 I loded namemono.bmp.

Then the following code for the button:

Var
B : TBitmap;
begin
Image3.Canvas.Draw(0,0,Image1.Picture.Bitmap);
Image2.Picture.Bitmap.TransparentColor := clBlack;
Image3.Canvas.Draw(0,0,Image2.Picture.Bitmap);
Image3.Picture.SaveToFile(CurFile); //Curfile is the destination filename
end;

This pastes the True color image onto the Image3 component and then pastes the Monochrome mask over the top making the background of the image a plain Magenta color ready for inclusion into my games.

The whole process takes less than three minutes from taking the picture to having the sprite ready in my game. Obviously this could be too long for a game with thousands of sprites but for puzzle games and other games requireing a small number of sprites this process will work fine.