Recent

Author Topic: [SOLVED] Graphics32: Assign TBitmap32 to TBitmap, black image  (Read 13144 times)

Fodox

  • New Member
  • *
  • Posts: 13
[SOLVED] Graphics32: Assign TBitmap32 to TBitmap, black image
« on: August 29, 2014, 05:52:56 pm »
Lazarus 1.2.2 + win7.

Simple question.
I have an image in a TImgView32 and I need to assigno to a simple TBitmap:

Code: [Select]
bmp.Assign(ImgView32.Bitmap);
I obtain a black image. What is wrong?

« Last Edit: August 30, 2014, 10:19:06 pm by Fodox »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Graphics32: Assign TBitmap32 to TBitmap, black image
« Reply #1 on: August 29, 2014, 06:33:05 pm »
Simple answer:
Most likely Graphics32:
1- Sets the size of the bitmap - where you get black image.
2- then it draws it - you need to call bmp.Canvas.Changed, maybe.

Fodox

  • New Member
  • *
  • Posts: 13
Re: Graphics32: Assign TBitmap32 to TBitmap, black image
« Reply #2 on: August 30, 2014, 10:18:42 pm »
Ok it works.
It would be nice to understand why you have to call "changed" manually, but the question will not be "simple" anymore, so... thank you very much!

Fod.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: [SOLVED] Graphics32: Assign TBitmap32 to TBitmap, black image
« Reply #3 on: August 30, 2014, 11:14:46 pm »
why you have to call "changed" manually
Because:
  bmp.Canvas is a memory canvas
    its handle is a memory DC,
  ====> any direct changes through a memory DC have no visual effect.

When Graphics32 draws ImgView32.Bitmap onto bmp, it is copying its contents to bmp's memory representation. It uses The handle bmp.Canvas.handle that is provided by the system (Windows in my case) and LCL has no way of knowing of any changes without a call to "changed".

Only after a call to "changed", the memory representation gets copied to the visual one.

Maybe bmp.assign should have called "changed", unless this design maintains compatibility with Delphi?

avys1

  • Newbie
  • Posts: 1
Re: [SOLVED] Graphics32: Assign TBitmap32 to TBitmap, black image
« Reply #4 on: October 08, 2014, 11:24:34 am »
>> ... unless this design maintains compatibility with Delphi?
On the contrary - this design does not maintain compatibility with Delphi.
I'm porting some Delphi code to Lazarus.  Delphi code was:

   captureclient(Control,bmp);
   jpg := TJPEGImage.Create;
   jpg.Assign(bmp);
   jpg.SaveToFile(FileName);


I've got a black image on the bmp oblect (doing bmp.SaveToFile resulted in a black image).
After reading this post, I changed the code:

   captureclient(Control,bmp);
   bmp.Canvas.Changed;        // Workaround for bitmap bug;
   jpg := TJPEGImage.Create;
   jpg.Assign(bmp);
   jpg.SaveToFile(FileName);


Now everything works fine.
Look like Delphi's doing Canvas.Changed internally after some operations, where the LCL implementattion does not.

Avy

Timewarp

  • Full Member
  • ***
  • Posts: 144

 

TinyPortal © 2005-2018