设置首页收藏本站在线聊天
授权版本:2024_09
开启左侧

hobject 转bitmap 图像大小会丢失,大家有啥好办法不

[复制链接]
siven 发表于 2024-2-21 11:24:48 | 显示全部楼层 |阅读模式
public void HObject2Bitmap8(HObject image, out Bitmap res)
{
    HTuple hpoint, type, width, height;
    const int Alpha = 255;
    HOperatorSet.GetImagePointer1(image, out hpoint, out type, out width, out height);
    res = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
    ColorPalette pal = res.Palette;
    for (int i = 0; i <= 255; i++)
    {
        pal.Entries[i] = 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);
}
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表