Solution for "A Graphics Object cannot be Created from an Image that has an Indexed Pixel Format"
错误信息
Solution for "A Graphics Object cannot be Created from an Image that has an Indexed Pixel Format"
排查问题
名称 | 值 | 类型 | |
---|---|---|---|
img.PixelFormat | Format8bppIndexed | System.Drawing.Imaging.PixelFormat |
当您访问/编辑以下类型的图像时,我们将收到错误“无法从具有索引像素格式的图像创建图形对象”
- PixelFormatUndefined
- PixelFormatDontCare
- PixelFormat1bppIndexed
- PixelFormat4bppIndexed
- PixelFormat8bppIndexed
- PixelFormat16bppGrayScale
- PixelFormat16bppARGB1555
解决方案
转换img为bitmap
C# 全选
Bitmap img = new Bitmap(new Bitmap( imag ));
C# 全选
try
{
// create Image Object using rear image byte[]
Image imag = Image.FromStream(new MemoryStream(imageR));
// Derive BitMap object using Image instance, so that you can avoid the issue
//"a graphics object cannot be created from an image that has an indexed pixel format"
Bitmap img = new Bitmap(new Bitmap( imag ));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 管理员