Recent

Author Topic: Why can't I get "Simple example" for BGRABitmap to work?  (Read 3550 times)

stab

  • Full Member
  • ***
  • Posts: 187
Why can't I get "Simple example" for BGRABitmap to work?
« on: July 23, 2013, 11:10:42 pm »
Hi,

Lazarus: ver 1.1
OS:         Windows 7/64bit
FPC:        ver. 2.7.1
SVN:        rev. 39352MP

Have tried to copy the code in "Simple example" for BGRABitmap like:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, BGRABitmap,
  BGRABitmapTypes, BGRATransform, BGRAGraphicControl;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  bmp: TBGRABitmap;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  bmp := TBGRABitmap.Create(100,100,BGRABlack); //creates a 100x100 pixels image with black background

   bmp.FillRect(20,20,60,60,BGRAWhite, dmSet); //draws a white square without transparency
   bmp.FillRect(40,40,80,80,BGRA(0,0,255,128), dmDrawWithTransparency); //draws a transparent blue square
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bmp.Free;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  bmp.Draw(Canvas, 0, 0, True); // draw the bitmap in opaque mode (faster)
end;

end.

But nothing is displayed.

What am i doing wrong?

Regards
stab :(


Jurassic Pork

  • Hero Member
  • *****
  • Posts: 837
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #1 on: July 24, 2013, 05:35:47 am »
hello Stab,

i have no problem to display the bitmap with your code with Lazarus windows 7 svn 1.1 Bgrabitmappack 7.2 .
The last version of bgrabitmap is here : http://sourceforge.net/p/lazpaint/code/HEAD/tree/bgrabitmap/

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

stab

  • Full Member
  • ***
  • Posts: 187
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #2 on: July 24, 2013, 10:54:45 am »
Thanks for answering,

Followed your suggestion and got Bgrabitmappack 7.2, but same result as before.
As a test I added:
  bmp.SaveToFile(ExtractFilepath(Application.Exename) + 'bml.png'); right after

  bmp.FillRect(40,40,80,80,BGRA(0,0,255,128), dmDrawWithTransparency); //draws a transparent blue square

and could verify that the calls to BGRABitmap had worked OK.

Of some peculiar drawing to a canvas doesn't work

/stab :'(

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #3 on: August 02, 2013, 08:34:33 am »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #4 on: August 02, 2013, 09:01:49 am »
Did you just straight copy-paste the code like that, or did you also link the FormCreate and so on to the TForm1 object in the IDE?

circular

  • Hero Member
  • *****
  • Posts: 3508
    • Personal webpage
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #5 on: August 31, 2013, 09:28:06 am »
It should work. Put a breakpoint on the bmp.Draw instruction: does it go through that instruction?
Conscience is the debugger of the mind

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8795
  • FPC developer.
Re: Why can't I get "Simple example" for BGRABitmap to work?
« Reply #6 on: August 31, 2013, 09:59:05 am »
Invalidate the form, so the system knows it should generate paint events for it?

Just add invalidate after the call.

 

TinyPortal © 2005-2018