Halcon读取jpg格式图片失败的处理方法
2017-11-28 20:43
411 查看
halcon读取jpg格式图片时,抛异常。最先想到的方法是用windows的画图软件或者PicPix软件将jpg格式的图片另存为BMP格式,但图片数量较多,这种方法不可取。
如下的方法,利用Graphics类中的DrawImage方法重新绘制不带图片格式的Bitmap,而后save为BMP格式的图片。代码如下 OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Image|*.bmp;*.png;*.jpg;*.jpeg;*.tiff",
FilterIndex = 1
};
dialog.Multiselect = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
string[] fileName = dialog.FileNames;
for (int i = 0; i < fileName.Length/3; i++)
{
Bitmap bitmap = new Bitmap(fileName[i]);
Bitmap image = new Bitmap(bitmap.Width, bitmap.Height);
using (Graphics graphics = Graphics.FromImage(image))
{
Rectangle destRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
Rectangle srcRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
graphics.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
graphics.Dispose();
}
image.Save(@"C:\Users\Administrator\Desktop\image_bmp\"+i.ToString()+".bmp", ImageFormat.Bmp);
}
}
如下的方法,利用Graphics类中的DrawImage方法重新绘制不带图片格式的Bitmap,而后save为BMP格式的图片。代码如下 OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Image|*.bmp;*.png;*.jpg;*.jpeg;*.tiff",
FilterIndex = 1
};
dialog.Multiselect = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
string[] fileName = dialog.FileNames;
for (int i = 0; i < fileName.Length/3; i++)
{
Bitmap bitmap = new Bitmap(fileName[i]);
Bitmap image = new Bitmap(bitmap.Width, bitmap.Height);
using (Graphics graphics = Graphics.FromImage(image))
{
Rectangle destRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
Rectangle srcRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
graphics.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
graphics.Dispose();
}
image.Save(@"C:\Users\Administrator\Desktop\image_bmp\"+i.ToString()+".bmp", ImageFormat.Bmp);
}
}
相关文章推荐
- halcon与C#混合编程(二)读取并处理图片
- python 读取、保存、二值化、灰度化图片+opencv处理图片的方法
- sd_setImageWithURL加载图片失败原因以及处理方法
- jQuery处理图片加载失败的常用方法
- jQuery处理图片加载失败的常用方法
- js 图片加载失败处理方法
- android FileReader 读取图片资源显示预览失败解决方法
- js 图片加载失败处理方法
- python从网络读取图片并直接进行处理的方法
- halcon与C#混合编程(二)读取并处理图片
- python从网络读取图片并直接进行处理的方法
- 图片加载失败裂开jquery和js的前端处理方法
- 图片加载失败之后的处理(引申一下img的complete和onload方法)
- asp.net 中 UEditor 图片和附件上传失败的处理方法
- AngularJS中如果ng-src 图片加载失败处理方法
- python 读取、保存、二值化、灰度化图片+opencv处理图片的方法
- Android处理图片OOM的若干方法小结
- 用C#读取图片的EXIF信息的方法(转)
- 如何读取二进制图片-.ashx一般处理程序 --1
- perl下载处理二进制数据(如tiff格式图片)的方法