Delphi中如何精确绘制特定区域或图像的一部分?
- 内容介绍
- 文章标签
- 相关推荐
本文共计414个文字,预计阅读时间需要2分钟。
我有一个普通的Bitmap加载PNG+Image。以下代码展示整个图像;但我需要的是图像下面的示例一样显示。基本上,我想尽量减少它将被绘制的位置。请注意,我不仅仅是因为有人问我是否可以列举的位置。
我有一个普通的Bitmap加载PNG Image.以下代码显示整个图像;但我要找的是像下面的示例一样显示.我基本上想要减少它将被绘制的虚拟“位置”.请注意,我不能仅仅因为有人问我可以枚举的原因来调整PaintBox的大小.我想我必须使用Rects和/或一些复制功能,但我自己也搞不清楚.有谁知道怎么办?procedure TForm1.PaintBox1Paint(Sender: TObject); begin PaintBox1.Canvas.Brush.Color := clBlack; PaintBox1.Brush.Style := bsSolid; PaintBox1.Canvas.FillRect(GameWindow.Screen.ClientRect); PaintBox1.Canvas.Draw(0, 0, FBitmap, FOpacity); end; 一种方法是修改paintbox画布的剪裁区域:
... IntersectClipRect(PaintBox1.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20); PaintBox1.Canvas.Draw(0, 0, FBitmap, FOpacity);
当然,我确定你知道你的Canvas.Draw调用中的0,0是坐标.你可以画到你喜欢的地方:
... FBitmap.Canvas.CopyRect(Rect(0, 0, 80, 80), FBitmap.Canvas, Rect(20, 20, 100, 100)); FBitmap.SetSize(80, 80); PaintBox1.Canvas.Draw(20, 20, FBitmap, FOpacity);
如果您不想剪切绘图框的区域,并且不想修改源位图(FBitmap),并且不想对其进行临时复制,则可以直接调用AlphaBlend而不是通过Canvas.画:
var BlendFn: TBlendFunction; begin BlendFn.BlendOp := AC_SRC_OVER; BlendFn.BlendFlags := 0; BlendFn.SourceConstantAlpha := FOpacity; BlendFn.AlphaFormat := AC_SRC_ALPHA; winapi.windows.AlphaBlend(PaintBox1.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20, FBitmap.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20, BlendFn);
本文共计414个文字,预计阅读时间需要2分钟。
我有一个普通的Bitmap加载PNG+Image。以下代码展示整个图像;但我需要的是图像下面的示例一样显示。基本上,我想尽量减少它将被绘制的位置。请注意,我不仅仅是因为有人问我是否可以列举的位置。
我有一个普通的Bitmap加载PNG Image.以下代码显示整个图像;但我要找的是像下面的示例一样显示.我基本上想要减少它将被绘制的虚拟“位置”.请注意,我不能仅仅因为有人问我可以枚举的原因来调整PaintBox的大小.我想我必须使用Rects和/或一些复制功能,但我自己也搞不清楚.有谁知道怎么办?procedure TForm1.PaintBox1Paint(Sender: TObject); begin PaintBox1.Canvas.Brush.Color := clBlack; PaintBox1.Brush.Style := bsSolid; PaintBox1.Canvas.FillRect(GameWindow.Screen.ClientRect); PaintBox1.Canvas.Draw(0, 0, FBitmap, FOpacity); end; 一种方法是修改paintbox画布的剪裁区域:
... IntersectClipRect(PaintBox1.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20); PaintBox1.Canvas.Draw(0, 0, FBitmap, FOpacity);
当然,我确定你知道你的Canvas.Draw调用中的0,0是坐标.你可以画到你喜欢的地方:
... FBitmap.Canvas.CopyRect(Rect(0, 0, 80, 80), FBitmap.Canvas, Rect(20, 20, 100, 100)); FBitmap.SetSize(80, 80); PaintBox1.Canvas.Draw(20, 20, FBitmap, FOpacity);
如果您不想剪切绘图框的区域,并且不想修改源位图(FBitmap),并且不想对其进行临时复制,则可以直接调用AlphaBlend而不是通过Canvas.画:
var BlendFn: TBlendFunction; begin BlendFn.BlendOp := AC_SRC_OVER; BlendFn.BlendFlags := 0; BlendFn.SourceConstantAlpha := FOpacity; BlendFn.AlphaFormat := AC_SRC_ALPHA; winapi.windows.AlphaBlend(PaintBox1.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20, FBitmap.Canvas.Handle, 20, 20, PaintBox1.Width - 20, PaintBox1.Height - 20, BlendFn);

