c#中如何调用API函数GdipSaveImageToStream ? c#中如何调用API函数GdipSaveImageToStream ? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Image和Stream有很好的转换啊,为什么一定要用API呢? 是啊,API中没这个函数,这是哪里的函数啊 不过可以用如下的声明来调用这个API:[DllImport("gdiplus.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]internal static extern int GdipSaveImageToStream(IntPtr image, UnsafeNativeMethods.IStream stream, ref Guid classId, IntPtr encoderParams); 我是想把从扫描仪出来的图像存到流中,然后直接在pictureBox中显示出来誰能帮帮忙? 就有这个构造函数啊:Bitmap bit = new Bitmap(stream); // // 摘要: // 从指定的数据流初始化 System.Drawing.Bitmap 类的新实例。 // // 参数: // stream: // 用于加载图像的数据流。 public Bitmap(Stream stream); hbxtlhx(平民百姓) 不过可以用如下的声明来调用这个API:[DllImport("gdiplus.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]internal static extern int GdipSaveImageToStream(IntPtr image, UnsafeNativeMethods.IStream stream, ref Guid classId, IntPtr encoderParams);------------------------能给个具体调用的过程吗?以前没有调用过API函数 从扫描仪得到的是IntPtr image的数据,怎样才能转为pictureBox可以显示的图像? 我是想把IntPtr image存到流中,然后再用Image.FromStream把它显示到pictureBox中,行得通吗? lz:你这个函数是第三方的SDK吧,如果是,hbxtlhx的方法应该可以实现你的要求 觉得你最好用Image或Bitmap来和Stream交互,最好不用API 下面的代码是将扫描得到的数据保存到文件和:public class Gdip { private static ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); private static bool GetCodecClsid(string filename, out Guid clsid) { clsid = Guid.Empty; string ext = Path.GetExtension(filename); if (ext == null) return false; ext = "*" + ext.ToUpper(); foreach (ImageCodecInfo codec in codecs) { if (codec.FilenameExtension.IndexOf(ext) >= 0) { clsid = codec.Clsid; return true; } } return false; }public static bool SaveDIBAs(string picname, IntPtr bminfo, IntPtr pixdat) { SaveFileDialog sd = new SaveFileDialog(); sd.FileName = picname; sd.Title = "Save bitmap as..."; sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|GIF file (*.gif)|*.gif|All files (*.*)|*.*"; sd.FilterIndex = 1; if (sd.ShowDialog() != DialogResult.OK) return false; Guid clsid; if (!GetCodecClsid(sd.FileName, out clsid)) { MessageBox.Show("Unknown picture format for extension " + Path.GetExtension(sd.FileName), "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information); return false; } IntPtr img = IntPtr.Zero; int st = GdipCreateBitmapFromGdiDib(bminfo, pixdat, ref img); if ((st != 0) || (img == IntPtr.Zero)) return false; st = GdipSaveImageToFile(img, sd.FileName, ref clsid, IntPtr.Zero); GdipDisposeImage(img); return st == 0; }[DllImport("gdiplus.dll", ExactSpelling = true)] internal static extern int GdipCreateBitmapFromGdiDib(IntPtr bminfo, IntPtr pixdat, ref IntPtr image);[DllImport("gdiplus.dll", ExactSpelling = true, CharSet = CharSet.Unicode)] internal static extern int GdipSaveImageToFile(IntPtr image, string filename, [In] ref Guid clsid, IntPtr encparams);[DllImport("gdiplus.dll", ExactSpelling = true)] internal static extern int GdipDisposeImage(IntPtr image);}我想把它改成将扫描得到的数据直接显示在pictureBox中,如何做? 有用过vs2012的吗?是不是也很耗资源?metro程序是不是只能用vs2012开发?只能通过微软那个商店安装? 在c#中利用委托进行冒泡排序 c# 如何打开mp3文件 请教高手,在C# ,如何读取PDF文件的内容???有没有第三方控件???? c# 读写注册表? javascript高手请进来,问一个问题 数组里项大小排序 只有30分了大家帮帮忙问两个C# 的问题(真的很急): filesystemwatcher 的一个重大问题 winform中 如何监听控件的拖拽事件已经结束? MDI窗体最前的问题! 子线程如何使用FolderBrowserDialog??
[DllImport("gdiplus.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
internal static extern int GdipSaveImageToStream(IntPtr image, UnsafeNativeMethods.IStream stream, ref Guid classId, IntPtr encoderParams);
誰能帮帮忙?
Bitmap bit = new Bitmap(stream);
// 摘要:
// 从指定的数据流初始化 System.Drawing.Bitmap 类的新实例。
//
// 参数:
// stream:
// 用于加载图像的数据流。
public Bitmap(Stream stream);
不过可以用如下的声明来调用这个API:
[DllImport("gdiplus.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
internal static extern int GdipSaveImageToStream(IntPtr image, UnsafeNativeMethods.IStream stream, ref Guid classId, IntPtr encoderParams);------------------------
能给个具体调用的过程吗?以前没有调用过API函数
{
private static ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); private static bool GetCodecClsid(string filename, out Guid clsid)
{
clsid = Guid.Empty;
string ext = Path.GetExtension(filename);
if (ext == null)
return false;
ext = "*" + ext.ToUpper();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FilenameExtension.IndexOf(ext) >= 0)
{
clsid = codec.Clsid;
return true;
}
}
return false;
}public static bool SaveDIBAs(string picname, IntPtr bminfo, IntPtr pixdat)
{
SaveFileDialog sd = new SaveFileDialog(); sd.FileName = picname;
sd.Title = "Save bitmap as...";
sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|GIF file (*.gif)|*.gif|All files (*.*)|*.*";
sd.FilterIndex = 1;
if (sd.ShowDialog() != DialogResult.OK)
return false; Guid clsid;
if (!GetCodecClsid(sd.FileName, out clsid))
{
MessageBox.Show("Unknown picture format for extension " + Path.GetExtension(sd.FileName),
"Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
} IntPtr img = IntPtr.Zero;
int st = GdipCreateBitmapFromGdiDib(bminfo, pixdat, ref img);
if ((st != 0) || (img == IntPtr.Zero))
return false; st = GdipSaveImageToFile(img, sd.FileName, ref clsid, IntPtr.Zero);
GdipDisposeImage(img);
return st == 0;
}[DllImport("gdiplus.dll", ExactSpelling = true)]
internal static extern int GdipCreateBitmapFromGdiDib(IntPtr bminfo, IntPtr pixdat, ref IntPtr image);[DllImport("gdiplus.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
internal static extern int GdipSaveImageToFile(IntPtr image, string filename, [In] ref Guid clsid, IntPtr encparams);[DllImport("gdiplus.dll", ExactSpelling = true)]
internal static extern int GdipDisposeImage(IntPtr image);
}我想把它改成将扫描得到的数据直接显示在pictureBox中,如何做?