MS CE C# 获取dgn文件缩略图

老师我想获取dgn文件的缩略图代码如下:

但是FromStream()去一直抛异常说参数无效,请问一下获取到的这个byte[]难道没有有效的图像格式?

或者还有其他办法获取缩略图吗?

Parents
  • 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;
            }
        }

    我简单写了一个类,具体代码自己研究

    例子示意图:

    ---------------------------------------------------------------

    中国市政工程西北设计研究院有限公司武汉分院


Reply
  • 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;
            }
        }

    我简单写了一个类,具体代码自己研究

    例子示意图:

    ---------------------------------------------------------------

    中国市政工程西北设计研究院有限公司武汉分院


Children