C# 通过 onPaint 方法保存图像
嗨,有人知道如何保存我创建的矩形中的图像吗?
protected override void OnPaint(PaintEventArgs e)
{
Bitmap bitmap = new Bitmap(@"Pictures/testing.jpg");
Image img = bitmap;
int width = testing.Width / 3;
int height = testing.Height / 3;
Rectangle destrect = new Rectangle(0, 0, width, height);
GraphicsUnit units = GraphicsUnit.Pixel;
System.Drawing.Imaging.ImageAttributes imageAttr= new System.Drawing.Imaging.ImageAttributes();
//1.1.jpg//
//e.Graphics.DrawImage(img,destrect,0,0, width, height, units, imageAttr);
//1.2.jpg//
e.Graphics.DrawImage(img, destrect, width, 0,width, height, units, imageAttr);
base.OnPaint(e);
}
我有裁剪后的所需图像,但我不知道如何保存..将不胜感激任何帮助。
Hi anyone knows how to save an image from the rectangle i created?
protected override void OnPaint(PaintEventArgs e)
{
Bitmap bitmap = new Bitmap(@"Pictures/testing.jpg");
Image img = bitmap;
int width = testing.Width / 3;
int height = testing.Height / 3;
Rectangle destrect = new Rectangle(0, 0, width, height);
GraphicsUnit units = GraphicsUnit.Pixel;
System.Drawing.Imaging.ImageAttributes imageAttr= new System.Drawing.Imaging.ImageAttributes();
//1.1.jpg//
//e.Graphics.DrawImage(img,destrect,0,0, width, height, units, imageAttr);
//1.2.jpg//
e.Graphics.DrawImage(img, destrect, width, 0,width, height, units, imageAttr);
base.OnPaint(e);
}
I have the desired image that is cropped but i don't know how to save .. Would greatly appreciate any help .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不管怎样,我自己得到了它,这是按钮点击事件的简单事件。
私人无效button1_Click(对象发送者,EventArgs e)
{
位图 哈哈 = 新位图(100, 100); ;
其中测试是我在构造函数中声明的原始位图图像。
anyhow, i got it myself, this is the simple one on button click event.
private void button1_Click(object sender, EventArgs e)
{
Bitmap lol = new Bitmap(100, 100); ;
where testing is my original bitmap image declared in constructor.