Recent

Author Topic: TCanvas.Draw(left,top,TBitmap); on Linux didn't work  (Read 14625 times)

dan59314

  • New Member
  • *
  • Posts: 38
TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« on: December 29, 2010, 03:18:09 am »
Any one have been successed on Linux( ubuntu 10) to use TCanvas.Draw(0,0,Tbitmap)?

I google for a long time, still got no solution. This shold be the same issue as mine.

http://62.166.198.202/view.php?id=7184

What I did is
  Step 1 : Create a TBitmap, pixelformat at pf24Bit. width:640, height:480
  Step 2 : Draw some shapes on it ( use scanline-painting with TBitmapa.RawImage.Data).
  Step 3 : Save TBitmap to File, and view the bmp file with ImageViewer, shows all the painted shapse without problem. 
 
So far, both Under Windows and Linux has no problem at all.

  Step 4 : I draw the tbitmap on a TPaintBox with  PaintBox1.Canvas.Draw(0, 0, aBitmap);

Then the paintbox shows the aBitmap in Windows, and it shows nothing in Linux.

Does it work to Draw TBitmap on TCanvas in Linux?

Thanks,

Daniel

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2512
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #1 on: December 29, 2010, 11:59:43 am »
Drawing on a canvas works, but modifying pixel data might not work.
Did you use Canvas.BeginUpdate/EndUpdate when modifying RawImage.Data ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #2 on: December 30, 2010, 02:06:39 am »
Drawing on a canvas works, but modifying pixel data might not work.
Did you use Canvas.BeginUpdate/EndUpdate when modifying RawImage.Data ?

  No, I use only TBitmap.BeginUpdate/EndUpdate, is there also a TCanvas.BeginUpdate/EndUpdate, too? Is that necessary to added before and after TCanvas.Draw/TCanvs.CopyRect?

  Thanks.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #3 on: December 30, 2010, 03:21:11 am »
Just a guess, does it show if you call Paintbox1.Repaint ? When drawing things its not always obvious that the buffers are "flipped" right.

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #4 on: December 30, 2010, 04:45:54 am »
Just a guess, does it show if you call Paintbox1.Repaint ? When drawing things its not always obvious that the buffers are "flipped" right.

No, it didn't work. Also there seems be no TCanvas.BeginUpdate/EndUpdate. Any other idea?

Why it has problem to call  TCanvas.Draw/CopyRect( left, top,  TBitmap) in Linux but the windows?



Thanks.

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #5 on: December 30, 2010, 09:03:31 am »
  Got an Idea.

  Since it successed on painting into Tbitmap(RawImage.Data), but failed while PaintBox1.Canvas.Draw(0, 0, aBitmap);

  Is it possible that TBitmap.Canvas didn't get updated, so the TBitmap.Canvas is empty?

  If yes, how to update TBitmap.Canvas?

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #6 on: December 31, 2010, 02:40:40 am »
I tried this way and it works.

   First save the painted TBitmap out, than load it again, and draw on TCanvas.

   ......  paint somethin on aBmp

   aBmp.SaveToFile('dummy.bmp');
   aBmp.LoadFromFile('dummy.bmp');
   PaintBox1.Canvas.Draw(0,0, aBmp);   ------->    Works.

   It seems TBitmap.LoadFromFile( ) make all the  TCanvas.Draw(0,0, TBitmap); works, 
   
   Any idea what could be the problem?

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #7 on: January 04, 2011, 07:36:37 am »
  Can anyone help?  I wonder the solution is almost there. But I know nothing about the TBitmap.LoadFromFile( );

  Once the TBitmap reloaded via TBitmap.LoadFromFile(), it can be drawn on TCanvas. I guess there must be the solution inside it. Please help.


Thanks,

Daniel

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #8 on: January 04, 2011, 01:39:21 pm »
Just did this test in Win32 Lazarus. TPaintBox and TButton on form, and it showed nothing on screen on load or after clicking button. Lock/Unlock didn't have effect:

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  with paintbox1.Canvas do begin
    //Lock;
    pen.Color:=clRed; brush.Color:=clWhite;
    Rectangle(2,2,50,50);
    //Unlock;
  end;
  paintbox1.Repaint;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FormCreate(nil);
end;
...so i'm as puzzled as you are.

But TImage has never yet failed me. You can set its width/height through Image.picture.bitmap
« Last Edit: January 04, 2011, 01:44:43 pm by User137 »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #9 on: January 04, 2011, 02:12:44 pm »
Repaint will delete what you have made.

TImage has a bitmap which will "save" your modifications.
« Last Edit: January 04, 2011, 02:17:59 pm by typo »

mdalacu

  • Full Member
  • ***
  • Posts: 209
    • dmSimpleApps
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #10 on: January 04, 2011, 02:35:13 pm »
This is working in Ubuntu 10.10

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    PaintBox1: TPaintBox;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  Btmp:TBitmap;
implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  PaintBox1.Canvas.Clear;
  PaintBox1.Canvas.CopyRect(rect(0,0,100,100),Btmp.Canvas,rect(0,0,100,100));
  PaintBox1.Canvas.Brush.Color:=clRed;
  PaintBox1.Canvas.Rectangle(10,10,50,50);
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  Btmp.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Btmp:=TBitmap.Create;
  Btmp.LoadFromFile('Flare.bmp');
end;

initialization
  {$I unit1.lrs}

end.
 

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #11 on: January 05, 2011, 01:37:48 am »
This is working in Ubuntu 10.10

I believe this works. But if you paint something on Btmp vis TBitmap.RowImage.Data, it won't show on TCanvas.  As I said, only after TBitmap.loadFromFile(), then it can be drawn on TCanvas.
« Last Edit: January 05, 2011, 01:39:43 am by dan59314 »

avra

  • Hero Member
  • *****
  • Posts: 2010
    • Additional info
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #12 on: January 05, 2011, 07:50:34 am »
So why don't you find and analyze TBitmap.LoadFromFile() to see what's the magic in it?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #13 on: January 05, 2011, 03:00:19 pm »
Repaint will delete what you have made.
Oops... removing Repaint did make the rectangle come visible  :)  Didn't load a bmp on bottom.

dan59314

  • New Member
  • *
  • Posts: 38
Re: TCanvas.Draw(left,top,TBitmap); on Linux didn't work
« Reply #14 on: January 11, 2011, 08:13:13 am »
So why don't you find and analyze TBitmap.LoadFromFile() to see what's the magic in it?

I wish I can. :(


Anyway, TImage should be the good way to me.

Thanks.

 

TinyPortal © 2005-2018