Recent

Author Topic: [SOLVED] How to Assign a Bitmap to the BGRAGraphicControl  (Read 1334 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] How to Assign a Bitmap to the BGRAGraphicControl
« on: July 16, 2019, 08:41:08 pm »
Hi,


I am trying to assign a bitmap to the BGRAGraphicControl, but get an error saying I can't.

Why?

Here is my code

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.  
  4. unit Unit1;
  5.  
  6. {$mode objfpc}{$H+}
  7.  
  8. interface
  9.  
  10. uses
  11.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  12.   BGRAGraphicControl, BGRABitmap, BGRABitmapTypes, BCTypes;
  13.  
  14. type
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     BGRAGraphicControl1: TBGRAGraphicControl;
  20.     Button1: TButton;
  21.     procedure BGRAGraphicControl1Paint(Sender: TObject);
  22.     procedure BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  23.     procedure Button1Click(Sender: TObject);
  24.     procedure FormDestroy(Sender: TObject);
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.   TheImage : TBGRABitmap;
  34.   //TheImage : TBitmap;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. begin
  44.     TheImage := TBGRABitmap.Create('test.jpg');
  45.     BGRAGraphicControl1.width:=TheImage.width;
  46.     BGRAGraphicControl1.height:=TheImage.height;
  47.     BGRAGraphicControl1.Assign(TheImage); {<-- ERROR - Can't Assign image}
  48.  
  49.     //TheImage := TBGRABitmap.Create;
  50.     //TheImage.LoadFromFile('test.jpg');
  51.     //TheImage.Canvas.FillRect(0,0,TheImage.Width,TheImage.Height);
  52.     //TheImage.SetSize(BGRAGraphicControl1.Width, BGRAGraphicControl1.Height);
  53.     //BGRAGraphicControl1.Canvas.Brush.Style:=bsClear;
  54.     //BGRAGraphicControl1.Canvas.Brush.Style:=bsClear;
  55.  
  56. end;
  57.  
  58. procedure TForm1.FormDestroy(Sender: TObject);
  59. begin
  60.   TheImage.Free;
  61. end;
  62.  
  63. procedure TForm1.BGRAGraphicControl1Paint(Sender: TObject);
  64. begin
  65.   if assigned(TheImage) then
  66.   begin
  67.     TheImage.Draw(Canvas,0,0,false); //true makes it opaque - false makes transparent
  68.     //BGRAGraphicControl1.Canvas.Draw(0,0,true);
  69.  
  70.   end;
  71.  
  72. end;
  73.  
  74. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap
  75.   );
  76. begin
  77.   //if assigned(TheImage) then
  78.      //TheImage.FillTransparent
  79. end;
  80.  
  81. end.
  82.  
  83. [\code]
  84.  
  85.  
« Last Edit: July 16, 2019, 11:56:59 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to Assign a Bitmap to the BGRAGraphicControl
« Reply #1 on: July 16, 2019, 09:52:33 pm »
TBGRAGraphicControl is a component that owns a TBGRABitmap - similar to TImage.

So the correct assign for your example is
Code: Pascal  [Select][+][-]
  1. BGRAGraphicControl1.Bitmap.Assign(TheImage);    
  2.  

Winni

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: How to Assign a Bitmap to the BGRAGraphicControl
« Reply #2 on: July 16, 2019, 11:56:39 pm »
TBGRAGraphicControl is a component that owns a TBGRABitmap - similar to TImage.

So the correct assign for your example is
Code: Pascal  [Select][+][-]
  1. BGRAGraphicControl1.Bitmap.Assign(TheImage);    
  2.  

Winni


Perfect!
I was missing just one word.
 :o
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018