Hobject转bitmap,高分辨率图像正常,小分辨率图片扭曲。这是怎么回事呢??求大神指导。。。
- /// <summary>
- /// 将Hobject转Bitmap
- /// </summary>
- /// <param name="image"></param>
- /// <returns></returns>
- public Bitmap HObject2Bpp8(HObject image)
- {
- HTuple hpoint, type, width, height;
- const int Alpha = 255;
- HOperatorSet.GetImagePointer1(image, out hpoint, out type, out width, out height);
- Bitmap res = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
- ColorPalette pal = res.Palette;
- for (int i = 0; i <= 255; i++)
- {
- pal.Entries = Color.FromArgb(Alpha, i, i, i);
- }
- res.Palette = pal;
- Rectangle rect = new Rectangle(0, 0, width, height);
- BitmapData bitmapData = res.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
- int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
- IntPtr ptr1 = bitmapData.Scan0;
- IntPtr ptr2 = hpoint;
- int bytes = width * height;
- byte[] rgbvalues = new byte[bytes];
- System.Runtime.InteropServices.Marshal.Copy(ptr2, rgbvalues, 0, bytes);
- System.Runtime.InteropServices.Marshal.Copy(rgbvalues, 0, ptr1, bytes);
- res.UnlockBits(bitmapData);
- return res;
- }
复制代码 |