附:将
tmpbitmap.Save(tmpstreamjpg, ImageFormat.Jpeg);//******************
改为
tmpbitmap.Save(tmpstreamjpg, ImageFormat.Bmp);//
也就是将保持格式改为BMP,内存消耗问题就不存在了。
急!!!!!!
tmpbitmap.Save(tmpstreamjpg, ImageFormat.Jpeg);//******************
改为
tmpbitmap.Save(tmpstreamjpg, ImageFormat.Bmp);//
也就是将保持格式改为BMP,内存消耗问题就不存在了。
急!!!!!!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.IO;//其余代码忽略....
[DllImport ("gdi32.dll",CharSet=CharSet.Auto)]
private static extern bool BitBlt(IntPtr pHdc, int iX, int iY, int iWidth, int iHeight, IntPtr pHdcSource, int iXSource, int iYSource, Int32 dw);
private const int SRC = 0xCC0020;
//FilePath 为保存图片路径
private void ConvertGVToBMP(string FilePath)
{
int width=100;
int height=100;
System.Drawing.Graphics g = dgv.CreateGraphics();
Bitmap ibitMap = new Bitmap(width, height, g);
Graphics ibitMap_gr = Graphics.FromImage(ibitMap);
IntPtr ibitMap_hdc = ibitMap_gr.GetHdc();
IntPtr me_hdc = g.GetHdc();
BitBlt(ibitMap_hdc, 0, 0, width, height, me_hdc, 0, 0, SRC);
g.ReleaseHdc(me_hdc);
ibitMap_gr.ReleaseHdc(ibitMap_hdc);
if (FilePath == "")
{
return;
}
else
{
ibitMap.Save(FilePath, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
Bitmap ibitMap = new Bitmap(width, height, g); 这两句有点问题 自己根据情况改一下 根据你的要求可以把这两句改为一句
Bitmap ibitMap = new Bitmap(@"/Windows/123.bmp");刚刚没注意 不好意思