TCanvas.Draw(left,top,TBitmap); on Linux didn't work lazarus / 39-Graphics ---------------------------------------------------------------------- dan59314 · 2010-12-29 02:18 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 · 2010-12-29 10:59 Drawing on a canvas works, but modifying pixel data might not work. Did you use Canvas.BeginUpdate/EndUpdate when modifying RawImage.Data ? ---------------------------------------------------------------------- dan59314 · 2010-12-30 01:06 Quote from: Marc on December 29, 2010, 11:59:43 amDrawing 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 · 2010-12-30 02:21 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 · 2010-12-30 03:45 Quote from: User137 on December 30, 2010, 03:21:11 amJust 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 · 2010-12-30 08:03 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 · 2010-12-31 01:40 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 · 2011-01-04 06:36 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 · 2011-01-04 12:39 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 ---------------------------------------------------------------------- typo · 2011-01-04 13:12 Repaint will delete what you have made. TImage has a bitmap which will "save" your modifications. ---------------------------------------------------------------------- mdalacu · 2011-01-04 13:35 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 · 2011-01-05 00:37 Quote from: mdalacu on January 04, 2011, 02:35:13 pmThis 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. ---------------------------------------------------------------------- avra · 2011-01-05 06:50 So why don't you find and analyze TBitmap.LoadFromFile() to see what's the magic in it? ---------------------------------------------------------------------- User137 · 2011-01-05 14:00 Quote from: typo on January 04, 2011, 02:12:44 pmRepaint will delete what you have made.Oops... removing Repaint did make the rectangle come visible    Didn't load a bmp on bottom. ---------------------------------------------------------------------- dan59314 · 2011-01-11 07:13 Quote from: avra on January 05, 2011, 07:50:34 amSo 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.