如何创建白色的1024×1024 RGB位图图像?
提出这个问题令人尴尬,却无法找到答案。
我徒劳地试了这个。
Image resultImage = new Bitmap(image1.Width, image1.Height, PixelFormat.Format24bppRgb); using (Graphics grp = Graphics.FromImage(resultImage)) { grp.FillRectangle( Brushes.White, 0, 0, image1.Width, image1.Height); resultImage = new Bitmap(image1.Width, image1.Height, grp); }
我基本上想用C#中的白色填充1024×1024 RGB位图图像。 我怎样才能做到这一点?
您正在为resultImage
分配一个新图像,从而覆盖您之前创建白色图像的尝试(顺便说一句,这应该会成功)。
所以只需删除该行
resultImage = new Bitmap(image1.Width, image1.Height, grp);
你几乎拥有它:
private Bitmap DrawFilledRectangle(int x, int y) { Bitmap bmp = new Bitmap(x, y); using (Graphics graph = Graphics.FromImage(bmp)) { Rectangle ImageSize = new Rectangle(0,0,x,y); graph.FillRectangle(Brushes.White, ImageSize); } return bmp; }
另一种方法,
创建单位位图
var b = new Bitmap(1, 1); b.SetPixel(0, 0, Color.White);
并扩大规模
上述就是C#学习教程:如何创建白色的1024×1024 RGB位图图像?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
var result = new Bitmap(b, 1024, 1024);
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/997365.html