windows – 如何使用每像素alpha将位图绘制到控件的画布上?
发布时间:2020-12-14 03:58:45 所属栏目:Windows 来源:网络整理
导读:题 将每像素alpha位图绘制到控件的画布上的最佳方法是什么? 我的位图数据存储在32位像素值的2d数组中. T32BitPixel = packed record Blue : byte; Green : byte; Red : byte; Alpha : byte;end; 我的控制权是TCustomTransparentControl的后代. 背景 对于我
题
将每像素alpha位图绘制到控件的画布上的最佳方法是什么? 我的位图数据存储在32位像素值的2d数组中. T32BitPixel = packed record Blue : byte; Green : byte; Red : byte; Alpha : byte; end; 我的控制权是TCustomTransparentControl的后代. 背景 对于我正在构建的GUI,我需要在其他控件和纹理背景上绘制半透明控件.使用AggPasMod(Anti-Grain Geometry的端口)创建控制图形. TCustomTransparentControl.Canvas.Handle提供对device context的绘图访问,但我不知道如何从那里blit像素数据. 解决方法
假设你的像素数组像图像行和像素一样,我会这样做. Canvas参数是目标画布,X和Y是坐标,其中位图将在目标画布中呈现,像素是像素数组:
type TPixel = packed record B: Byte; G: Byte; R: Byte; A: Byte; end; TPixelArray = array of array of TPixel; procedure RenderBitmap(Canvas: TCanvas; X,Y: Integer; Pixels: TPixelArray); var I: Integer; Size: Integer; Bitmap: TBitmap; BlendFunction: TBlendFunction; begin Bitmap := TBitmap.Create; try Bitmap.PixelFormat := pf32bit; Bitmap.Width := Length(Pixels[0]); Bitmap.Height := Length(Pixels); Size := Bitmap.Width * SizeOf(TPixel); for I := 0 to Bitmap.Height - 1 do Move(Pixels[I][0],Bitmap.ScanLine[I]^,Size); BlendFunction.BlendOp := AC_SRC_OVER; BlendFunction.BlendFlags := 0; BlendFunction.SourceConstantAlpha := 255; BlendFunction.AlphaFormat := AC_SRC_ALPHA; AlphaBlend(Canvas.Handle,X,Y,Bitmap.Width,Bitmap.Height,Bitmap.Canvas.Handle,BlendFunction); finally Bitmap.Free; end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- OpenCV、OpenCL、OpenGL、OpenMP的区别
- 二十三种设计模式[18] - 备忘录模式(Memento Pattern)
- drop \u0026\u0026!has.j出错:使用sum(complete.
- windows上传文件到 linux的hdfs
- WPF中的IWin32Window
- 如何防止在UWP中的任务切换器中显示
- windows-7 – 如何在Windows 7上使用Wireshark监控VPN流量?
- Windows 2008上的SSTP无法向任一方向ping
- windows-server-2008 – “DEL:”在AD对象的Distinguished
- windows – 强制环境变量更改立即生效
推荐文章
站长推荐
热点阅读