国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# Bitmap 復(fù)制的小例子

2020-01-24 03:07:11
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

public Bitmap CopyBitmap(Bitmap source)
{
    int depth = Bitmap.GetPixelFormatSize(source.PixelFormat);

    if (depth != 8 && depth != 24 && depth != 32)
    {
        return null;
    }

    Bitmap destination = new Bitmap(source.Width, source.Height, source.PixelFormat);

    BitmapData source_bitmapdata = null;
    BitmapData destination_bitmapdata = null;

    try
    {
        source_bitmapdata = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadWrite,
                                        source.PixelFormat);
        destination_bitmapdata = destination.LockBits(new Rectangle(0, 0, destination.Width, destination.Height), ImageLockMode.ReadWrite,
                                        destination.PixelFormat);

        unsafe
        {
            byte* source_ptr = (byte*)source_bitmapdata.Scan0;
            byte* destination_ptr = (byte*)destination_bitmapdata.Scan0;

            for (int i = 0; i < (source.Width * source.Height * (depth / 8)); i++)
            {
                *destination_ptr = *source_ptr;
                source_ptr++;
                destination_ptr++;
            }
        }

        source.UnlockBits(source_bitmapdata);
        destination.UnlockBits(destination_bitmapdata);

        return destination;
    }
    catch
    {
        destination.Dispose();
        return null;
    }
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 揭阳市| 长白| 昌乐县| 浦江县| 宣武区| 铜鼓县| 津南区| 兰西县| 常熟市| 时尚| 遂川县| 广河县| 枣庄市| 米脂县| 石屏县| 阿克陶县| 仙居县| 新巴尔虎右旗| 宝坻区| 凤冈县| 封丘县| 竹溪县| 德安县| 色达县| 镇平县| 崇文区| 卓资县| 龙里县| 徐州市| 瑞丽市| 吉木萨尔县| 东港市| 彭泽县| 八宿县| 博罗县| 凤冈县| 盖州市| 武隆县| 晋宁县| 紫金县| 万荣县|