图片在C#中的位置 [英] position of picture in C#

查看:450
本文介绍了图片在C#中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bitmap ax = new Bitmap(300, 300);
Rectangle rc = new Rectangle(0, 0, 300, 300);
this.DrawToBitmap(ax, rc);
pictureBox1.Image = ax;



运行此代码后,我们得到了一部分形式的图像(从point(0,0)到point(300,300)),但是我想要从point(300,300)到point(600,600)的图像.
我该怎么做?



after running this code we have an image of part of form (from point(0,0) to point(300,300)) but i want an image from point(300,300) to point(600,600).
How I can do it?

推荐答案

DrawToBitmap仅从源控件的TLHC中绘制,因为它假定整个控件(在这种情况下,可能是整个窗体) ) 将被要求.如果只需要一部分,则需要将整个控件绘制到合适的位图中,然后将该图像的一部分绘制到新的位图中.
DrawToBitmap only draws from the TLHC of the source control, as it assumes that the whole control (in this case, probably an entire form) will be required. If you want just a portion, then you need to draw the whole control into a suitable bitmap, then draw a portion of that image into a new bitmap.
Bitmap imageOfControl = new Bitmap(600, 600);
Rectangle rc = new Rectangle(0, 0, 600, 600);
this.DrawToBitmap(imageOfControl , rc);
Bitmap ax = new Bitmap(300,300);
using (Graphics g = Graphics.FromImage(ax))
   {
   g.DrawImage(imageOfControl, new Rectangle (300, 300, 300, 300), new Rectangle(0, 0, 300, 300), GraphicsUnit.Pixel);
   }
imageOfControl.Dispose();
pictureBox1.Image = ax;


pictureBox1必须是窗体上的控件.尝试将图片框移动到(300,300)的原点.
pictureBox1 must be a control on the form. Try moving the picture box to an origin of (300, 300).


这篇关于图片在C#中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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