老师我想获取dgn文件的缩略图代码如下:
但是FromStream()去一直抛异常说参数无效,请问一下获取到的这个byte[]难道没有有效的图像格式?
或者还有其他办法获取缩略图吗?
目前MstnCE C#公开的资料太少,推测应该是获得的这个Thumbnail格式与你用的系统的Image.FromStream要求的格式不一致从而导致异常。
我们会在内部咨询相关专家,有结果后在此帖答复您。
符老师, 同问。
public class DgnThumbnail { [DllImport("GdiPlus.dll", CharSet = CharSet.Unicode)] private static extern int GdipCreateBitmapFromGdiDib(IntPtr pBIH, IntPtr pPix, out IntPtr pBitmap); public static Bitmap CreateThumbnail(DgnFile df) { byte[] thumbnail = df.Thumbnail; Bitmap image = null; if (thumbnail != null) { IntPtr num = Marshal.AllocHGlobal(thumbnail.Length - 4); Marshal.Copy(thumbnail, 4, num, thumbnail.Length - 4); try { IntPtr pPix = new IntPtr(num.ToInt64() + (long)Marshal.SizeOf(typeof(Structs.BITMAPINFOHEADER)) + 1024L); MethodInfo method = typeof(Bitmap).GetMethod("FromGDIplus", BindingFlags.Static | BindingFlags.NonPublic); if (method != (MethodInfo)null) { IntPtr pBitmap = IntPtr.Zero; if (GdipCreateBitmapFromGdiDib(num, pPix, out pBitmap) == 0) { if (pBitmap != IntPtr.Zero) image= (Bitmap)method.Invoke((object)null, new object[1] {(object) pBitmap }); } } } catch (Exception ex) { } finally { Marshal.FreeHGlobal(num); } } return image; } }
我简单写了一个类,具体代码自己研究
例子示意图:
---------------------------------------------------------------
中国市政工程西北设计研究院有限公司武汉分院
多谢 郑哥