如何将图像的一部分变成PictureBox的? [英] how to insert part of image into picturebox?

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

问题描述

我真的不知道,如果它可以插入图像的一部分进入PictureBox的,但我想创建一个图像大小500 * 500像素,然后用它作为连接小50 * 50片零件通过设置pictureboxes ...

I'm not really sure if it is possible to insert a part of image into picturebox, but I would like to create an image 500*500 pixels in size and then use the parts of it as small connectable 50*50 pieces by setting the location of image inside the pictureboxes...

什么是通过使用图形相似的可能吗?我不是很熟悉的话......(我说的是C#窗体应用程序...)

Is anything similar possible through use of graphics? I'm not very familiar with it... (I am talking about C# forms application...)

推荐答案

在一些搜索和我已经找到了解决方案,几个人尝试的时间,这不是我自己的,但可悲的是我已经忘了在哪里我把它从:

After some time of searching and few personal attempts I have found a solution, this isn't my own, but sadly I have forgot where did I took it from:

   private static Image cropImage(Image img, Rectangle cropArea)
   {
       Bitmap bmpImage = new Bitmap(img);
       Bitmap bmpCrop = bmpImage.Clone(cropArea,
       bmpImage.PixelFormat);
       return (Image)(bmpCrop);
   }

这将创建裁剪图像,你现在可以在代码中使用它。示例:

This will created cropped image, you can now use it in code. SAMPLE:

   Picturebox P = new Picturebox;
   P.BackgroundImage = cropImage(ImageThatWillBeCropped, new Rectangle(0,0,50,50));

如果有人发现这个有用的,需要解释的矩形,请随时提问:)

If anyone finds this useful and needs explanation for rectangle, please, feel free to ask :)

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

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