BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help needed

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
AHM
Guest





PostPosted: Fri Jan 14, 2005 6:20 pm    Post subject: Help needed Reply with quote



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





PostPosted: Fri Jan 14, 2005 6:29 pm    Post subject: Re: Help needed Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.