Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 2720|回复: 0

delphi和 lazarus 图形处理区别

[复制链接]

该用户从未签到

发表于 2012-7-14 09:28:35 | 显示全部楼层 |阅读模式
首先需要记住的事情是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.

评分

参与人数 1威望 +4 收起 理由
猫工 + 4 优秀文章,支持!n神马都是浮云!

查看全部评分

回复

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 23:54 , Processed in 0.055070 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表