Recent

Author Topic: Graphics 32 and Tbitmap32  (Read 2452 times)

clintonb

  • New Member
  • *
  • Posts: 18
Graphics 32 and Tbitmap32
« on: May 21, 2020, 11:17:50 pm »
I have had an issue with the Tbitmap32.  To fix the problem i made a smaller program that just tried to load from a file and then save it//display it but i just keep getting a black background.

I made an even simpler application that creates a bitmap; draws on the canvas and then tries to assign and save it.  Eveything that is returned is a black background.  I tried a suggestion calling test.changed and then test.canvas.changed

test:=Tbitmap32.create(TLCLBackend);

     test.beginupdate;
     test.setsize(300,300);

     test.Canvas.moveto(0,0);
     test.canvas.Pen.Color:=clred;
     test.canvas.pen.width:=5;
     test.canvas.lineto(100,100);
     test.canvas.Brush.Color:=clred;
     test.canvas.Brush.Style:=bssolid;
     test.canvas.FillRect(0,0,100,100);
     test.endupdate;
     test.Canvas.Changed;

     image1.bitmap.assign(test);
     test.savetofile('/home/[username]/Desktop/Blank image.bmp');
     

Im using 64 bit linux and im using the latest library from the online packagemanager but no matter what i try i cannot get anything other that a black background.  Is there something i am missing or is there a very basic application that demonstrates the proper usage for this library?

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Graphics 32 and Tbitmap32
« Reply #1 on: May 21, 2020, 11:58:25 pm »
You draw something (Bitmap32) and then want to show the result with an standard canvas TIMAGE ????
Use TImage32 from the lib!
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

clintonb

  • New Member
  • *
  • Posts: 18
Re: Graphics 32 and Tbitmap32
« Reply #2 on: May 22, 2020, 12:25:34 am »
I might be misunderstanding what you are saying but image1 is a Timage32 that was just pasted onto the form.  The bottom line still ends with the image being a blank black canvas which shows in the file that it saves as well.

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Graphics 32 and Tbitmap32
« Reply #3 on: May 22, 2020, 01:16:19 am »
It's been a very long time since I did a Delphi project with Graphics32. As its name says, Graphics 32 is a 32-bit library, this means the every color consists of 3 bytes for red, green and blue as well as one more byte for the alpha channel where 0 means complete transparency and $FF complete opaqueness.

You fill the Graphics32 canvas with the color clRed which is defined in unit graphics as $000000FF - the two 0s after the $ are the alpha channel - complete transparency. You should use the color declarations defined in unit GR32, I just looked: there is a clRed32 where the alpha channel is $FF.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Graphics 32 and Tbitmap32
« Reply #4 on: May 22, 2020, 07:16:01 am »
Don't draw on/with the standard canvas if you need transparent pixels, the example shows nothing that can't be done with a normal bitmap. Use the GR32 routines... and the TImage in GR32 looks like this "Image321"... There's no Pen.Color in GR32 (BMP32.PenColor:= ...). There is no clRed only clTrRed32 or clRed32...  You are using the wrong canvas!  :P
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Graphics 32 and Tbitmap32
« Reply #5 on: May 22, 2020, 07:51:28 am »
This works for me ...  :)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes,SysUtils,Forms,Controls,Graphics,GR32,ExtCtrls,StdCtrls;
  6. type
  7.   TForm1 = class(TForm)
  8.     Button1: TButton;
  9.     procedure Button1Click(Sender: TObject);
  10.   private
  11.  
  12.   public
  13.  
  14.   end;
  15. var
  16.   Form1: TForm1;
  17. implementation
  18. {$R *.lfm}
  19.  
  20. procedure TForm1.Button1Click(Sender: TObject);
  21. var
  22.  BMP32: TBitmap32;
  23.  IMG: TImage;
  24. begin
  25.   BMP32:= TBitmap32.Create(300,300);
  26.   Try
  27.    BMP32.FillRect(0,0,300,300,clRed32);
  28.    BMP32.SaveToFile('BMP32.bmp');
  29.    IMG:= TImage.Create(Self);
  30.    IMG.Picture.Assign(BMP32);
  31.    IMG.Parent:= Self;
  32.   Finally
  33.    BMP32.Free;
  34.   End;
  35. end;
  36.  
  37. end.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

clintonb

  • New Member
  • *
  • Posts: 18
Re: Graphics 32 and Tbitmap32
« Reply #6 on: May 22, 2020, 07:13:27 pm »
Don't draw on/with the standard canvas if you need transparent pixels, the example shows nothing that can't be done with a normal bitmap. Use the GR32 routines... and the TImage in GR32 looks like this "Image321"... There's no Pen.Color in GR32 (BMP32.PenColor:= ...). There is no clRed only clTrRed32 or clRed32...  You are using the wrong canvas!  :P

And that good people is conclusive prrof that i am absolutely useless after 8pm.  Thanks mate  ::)

 

TinyPortal © 2005-2018