如何绘制图像的一部分? [英] How to draw part of a image?

查看:168
本文介绍了如何绘制图像的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经加载了PNGImage一个普通的位图。下面code显示了整个图像;但我所寻找的是显示如下图所示例如样本。我想基本上能够减少虚拟地点哪里会画。请注意,我不能只通过的原因,如果有人问我能列举调整颜料盒。我想我必须使用Rects和或某些复制功能,但我不能用自己弄清楚。有谁知道该怎么办?

I have an ordinary Bitmap loaded with a PNGImage. The following code shows the whole image; but what I am looking for is to show like the sample below for example. I want basically to reduce the virtual "place" where it would be painted. Note that I can't just resize the PaintBox by reasons I can enumerate if someone asks. I guess I have to use Rects and or some Copy function, but I could not figure out by myself. Does anyone know how to do?

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;

推荐答案

的一种方法是修改你的颜料盒的画布的剪辑区域:

One way is to modify the clipping region of your paintbox's canvas:

...
IntersectClipRect(PaintBox1.Canvas.Handle, 20, 20,
    PaintBox1.Width - 20, PaintBox1.Height - 20);
PaintBox1.Canvas.Draw(0, 0, FBitmap, FOpacity);


当然,我敢肯定,你知道,(0,0 Canvas.Draw 通话是坐标可以绘制到徘徊无论你喜欢:


Of course, I'm sure you're aware that the (0, 0 in your Canvas.Draw call are coordinates. You can draw to whereever you like:

...
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.Draw

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);

这篇关于如何绘制图像的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆