C#图像空白图像、空白

2023-09-03 12:49:08 作者:藏匿

我有一个形象,是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.

Word图片显示不出来怎么办 Word图片显空白的解决办法 电脑教程

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