|
首先需要记住的事情是Lazarus是独立于使用平台的,所以任何使用Windows API功能的问题都不值得讨论。比如像ScanLine这样的方法并不为Lazarus所支持,因为它是为设备独立的位图文件而设计的,并且使用了GDI32.dll中的函数。
Bear in mind that if you do not specify the height and width of your TBitmap it will have the standard one, which is quite small.
A fading example
Say you want to make a Fading picture. In Delphi you could do something like:typePRGBTripleArray = ^TRGBTripleArray;TRGBTripleArray = array[0..32767] of TRGBTriple;procedure TForm1.FadeIn(aBitMap: TBitMap);varBitmap, BaseBitmap: TBitmap;Row, BaseRow: PRGBTripleArray;x, y, step: integer;beginBitmap := TBitmap.Create;tryBitmap.PixelFormat := pf32bit; // or pf24bitBitmap.Assign(aBitMap);BaseBitmap := TBitmap.Create;tryBaseBitmap.PixelFormat := pf32bit;BaseBitmap.Assign(Bitmap);for step := 0 to 32 do beginfor y := 0 to (Bitmap.Height - 1) do beginBaseRow := BaseBitmap.Scanline[y];Row := Bitmap.Scanline[y];for x := 0 to (Bitmap.Width - 1) do beginRow[x].rgbtRed := (step * BaseRow[x].rgbtRed) shr 5;Row[x].rgbtGreen := (step * BaseRow[x].rgbtGreen) shr 5; // FadingRow[x].rgbtBlue := (step * BaseRow[x].rgbtBlue) shr 5;end;end;Form1.Canvas.Draw(0, 0, Bitmap);InvalidateRect(Form1.Handle, nil, False);RedrawWindow(Form1.Handle, nil, 0, RDW_UPDATENOW);end;finallyBaseBitmap.Free;end;finallyBitmap.Free;end;end;
This function in Lazarus could be implemented like:uses LCLType, // HBitmap typeIntfGraphics, // TLazIntfImage typefpImage; // TFPColor type...procedure TForm1.FadeIn(ABitMap: TBitMap);varSrcIntfImg, TempIntfImg: TLazIntfImage;ImgHandle,ImgMaskHandle: HBitmap;FadeStep: Integer;px, py: Integer;CurColor: TFPColor;TempBitmap: TBitmap;beginSrcIntfImg:=TLazIntfImage.Create(0,0);SrcIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);TempIntfImg:=TLazIntfImage.Create(0,0);TempIntfImg.LoadFromBitmap(ABitmap.Handle,ABitmap.MaskHandle);TempBitmap:=TBitmap.Create;for FadeStep:=1 to 32 do beginfor py:=0 to SrcIntfImg.Height-1 do beginfor px:=0 to SrcIntfImg.Width-1 do beginCurColor:=SrcIntfImg.Colors[px,py];CurColor.Red:=(CurColor.Red*FadeStep) shr 5;CurColor.Green:=(CurColor.Green*FadeStep) shr 5;CurColor.Blue:=(CurColor.Blue*FadeStep) shr 5;TempIntfImg.Colors[px,py]:=CurColor;end;end;TempIntfImg.CreateBitmap(ImgHandle,ImgMaskHandle,false);TempBitmap.Handle:=ImgHandle;TempBitmap.MaskHandle:=ImgMaskHandle;Canvas.Draw(0,0,TempBitmap);end;SrcIntfImg.Free;TempIntfImg.Free;TempBitmap.Free;end;
The Lazarus code on this page has been taken from the $LazarusPath/examples/lazintfimage/fadein1.lpi project. So if you want a flying start with graphics programming take a closer look at this example. |
评分
-
查看全部评分
|