Jump to content
A-man

copying a bitmap

Recommended Posts

If i have something like image1 := loadbitmap('path') (pretend its a real path), will image2 := image1 make image2 a copy of the first bitmap? I have a code with that setup and I'm not sure it's working, and don't know how to test whether or not it is. Hopefully someone here would know. I'm pretty sure loadbitmap just returns an integer which is an index to the image it is storing, so it should work in theory.

Link to comment
Share on other sites

Heres a simple procedure

 

[scar]

Function CopyBitmap(BMP: Integer): Integer;

Var

W,H: Integer;

S: String;

Begin

GetBitmapSize(BMP, W, H);

S := BitmapToString(BMP);

Result := BitmapFromString(W, H, S);

end;

 

Var

BMP, BMPcopy: Integer;

begin

BMP := BitmapFromString(100,100,'');

CopyClientToBitmap(BMP, 0, 0, 99 ,99); // Test Orginal Bitmap

 

BMPcopy := CopyBitmap(BMP); // create a copy

FastDrawClear(BMP, clBlack); // Fill orginal bitmap black

 

DebugBitmap(BMP); // display orginal all black

wait(400);

DebugBitmap(BMPcopy); // display the copy which should show the client

 

Freebitmap(BMP); // free bitmaps

Freebitmap(BMPcopy);

end.

[/scar]

 

---------- Post added at 03:55 AM ---------- Previous post was at 03:00 AM ----------

 

This actually copy's the bitmap into a new bitmap so if you wanted to edit the first bitmap without loosing the original you could.

 

if you did what you said, the original bitmap would be edited when ever your edited the copy, an example is below. If i free the original bitmap before i debug the copy of the bitmap i get an error of bitmap not assigned. Thi9s is because you are working with bitmap indexs and not the entire data fro the bitmap.

[scar]

Var

BMP, BMPcopy: Integer;

begin

BMP := BitmapFromString(100,100,'');

CopyClientToBitmap(BMP, 0, 0, 99 ,99); // Test Orginal Bitmap

BMPcopy := BMP;

FreeBitmap(BMP);

debugbitmap(BMPcopy);

end.

[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...