 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
AHM Guest
|
Posted: Fri Jan 14, 2005 6:20 pm Post subject: Help needed |
|
|
Why can't I skip the loading of a background bitmap? If I don't include
that line then nothing will be drawn on the image. If I remove
Bitmap.LoadFromFile('imagesbackground.bmp');
is there then some properties I should set myself for the code to work?
begin
Image := TImage.Create(nil);
Image.Left := 0;
Image.Parent := MyForm;
Image.Top := 0;
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('imagesbackground.bmp'); // This line
GIF := TGIFImage.Create;
GIF.LoadFromFile('imagespiece.gif');
Piece := TBitmap.Create;
Piece.Assign(GIF.Bitmap);
GIF.Free;
for X := 0 to Piece.Width - 1 do
for Y := 0 to Piece.Height - 1 do
if (Piece.Canvas.Pixels[X, Y] <> clWhite) then
Bitmap.Canvas.Pixels[X, Y] := Piece.Canvas.Pixels[X, Y];
Piece.Free;
Image.Picture.Assign(Bitmap);
end;
|
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Fri Jan 14, 2005 6:29 pm Post subject: Re: Help needed |
|
|
AHM wrote:
| Quote: | Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('imagesbackground.bmp'); // This line
GIF := TGIFImage.Create;
GIF.LoadFromFile('imagespiece.gif');
Piece := TBitmap.Create;
Piece.Assign(GIF.Bitmap);
GIF.Free;
for X := 0 to Piece.Width - 1 do
for Y := 0 to Piece.Height - 1 do
if (Piece.Canvas.Pixels[X, Y] <> clWhite) then
Bitmap.Canvas.Pixels[X, Y] := Piece.Canvas.Pixels[X, Y];
|
That you're loading a file into the Bitmap variable isn't what's
important. What's important is one of the side effects of loading a
file: The bitmap gets resized to accomodate the file. A brand-new
TBitmap instance has Width = Height = 0, so when you try to set its
Pixels property, there are no pixels to set.
When you load the bitmap file, Bitmap's size grows to the size of the
image. You can skip that step and instead just set Bitmap's size to
match that of Piece.
You shouldn't need to do all that pixel-by-pixel processing, though. The
GIF image should already know which of its pixels are transparent:
Bitmap.Canvas.Draw(0, 0, GIF);
--
Rob
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|