C#图像空白 [英] C# image whitespace

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

问题描述

我有一个形象,是240×320(纵向iPhone摄像头的图像),我需要以编程方式(在C#)加入白酒吧向两侧增加了完整的图像大小为320x320起。我不想缩放图像,因为这会搞乱宽高比。

我已经找到了很多有关如何删除白条用C#,但没有有关如何添加这些信息。我很茫然。没有人有任何的输入,可能导致我的正确方向?

多谢你, 布雷特

解决方案

 使用(System.Drawing.Image对象SRC = System.Drawing.Image.FromFile(picture.jpg))
{
       使用(BMP位图=新位图(320,320))
       {
                图形G = Graphics.FromImage(BMP);
                g.Clear(Color.White);
                g.DrawImageUnscaled(源,60,0,240,320);
                bmp.Save(file.jpg,ImageFormat.Jpeg);
       }
}
 

记住使用后处置的对象;)

I have an image that is 240x320 (iphone camera image in portrait), and I need to programmatically (in C#) add white "bars" to the sides increasing the full image size to 320x320. I don't want to scale the image because that would mess up the aspect ratio.

I have found a lot of info about how to remove white bars with c#, but nothing about how to add them. I am at a loss. Does anyone have any input that might lead me the correct direction?

Thanks a bunch, Brett

解决方案

using (System.Drawing.Image src = System.Drawing.Image.FromFile("picture.jpg"))
{
       using (Bitmap bmp = new Bitmap(320, 320))
       {
                Graphics g = Graphics.FromImage(bmp);
                g.Clear(Color.White);
                g.DrawImageUnscaled(src, 60, 0, 240, 320);
                bmp.Save("file.jpg", ImageFormat.Jpeg);
       }
}

Remember to dispose the object after use ;)

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

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