如何提高图像处理速度,以及保存文件的问题
1 我正在研究图像处理,基本都是颜色处理,取点,画点,速度很慢,请问有没有什么改进方法?
现在函数都是通过菜单激活的,单击菜单之后,程序就假死了(菜单不收回去),几秒内毫无反应,直到处理完毕,请问如何解决?
是否读入到内存可以加快速度,还是取数组[width,height,3],个人感觉都很慢
2 还有保存文件时,是不是static 图像变量无法保存,我用bitmap转存才保存的,
3 保存的是否用Switch判断文件名中的后缀很麻烦,是否有专门的函数取得ImageFormat
------解决方案--------------------1、如果要让菜单收回去,用this.Update()或Application.DoEvents()刷新一下就行了,但主程序依然假死,推荐用多线程。
3、用Image.RawFormat判断
下面是网上搜来的:
ImageFormatUndefined := "{B96B3CA9-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatMemoryBMP := "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatBMP := "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatEMF := "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatWMF := "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatJPEG := "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatPNG := "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatGIF := "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatTIFF := "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatEXIF := "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E} "
ImageFormatIcon := "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E} "
ImageCodecBMP := "{557CF400-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecJPG := "{557CF401-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecGIF := "{557CF402-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecEMF := "{557CF403-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecWMF := "{557CF404-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecTIF := "{557CF405-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecPNG := "{557CF406-1A04-11D3-9A73-0000F81EF32E} "
ImageCodecICO := "{557CF407-1A04-11D3-9A73-0000F81EF32E} "
; JPEG
EncoderTransformation := "{8D0EB2D1-A58E-4EA8-AA14-108074B7B6F9} "
EncoderQuality := "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB} "
EncoderLuminanceTable := "{EDB33BCE-0266-4A77-B904-27216099E717} "
EncoderChrominanceTable := "{F2E455DC-09B3-4316-8260-676ADA32481C} "
; TIFF
EncoderCompression := "{E09D739D-CCD4-44EE-8EBA-3FBF8BE4FC58} "
EncoderColorDepth := "{66087055-AD66-4C7C-9A18-38A2310B8337} "
EncoderSaveFlag := "{292266FC-AC40-47BF-8CFC-A85B89A655DE} "
------解决方案--------------------using System.Threading;
using System.Drawing;
Thread thread = new Thread(new ThreadStart(fun));
thread.Name = "DrawBMP ";
thread.Start();
void fun()
{
Bitmap bmp = new Bitmap( "file.bmp "); // 多种构造,请根据情况选择,看SDK。
bmp.Save( "newfile ", System.Drawing.Imaging.ImageFormat.Jpeg);//很多种文件类型可选。
}
双倍缓冲作图:
http://www.cnblogs.com/Bear-Study-Hard/archive/2006/03/22/355468.html
------解决方案--------------------不好意思,想起来了:双倍缓冲,就是声明一个Bitmap或者Image(请自己测试),然后在对这个对象画图,其实就是不直接在界面上画。最后重画整个图像。
protected override void OnPaint(PaintEventArgs e)
{
Graphics displayGraphics = e.Graphics;
Random r = new Random();
Image i = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
Graphics g = Graphics.FromImage(i);
g.FillRectangle(Brushes.White, ClientRectangle);
Color c = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
using (Pen p = new Pen(c, 1))