源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C# Bitmap 复制的小例子

  • 时间:2021-05-20 15:36 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C# Bitmap 复制的小例子
[u]复制代码[/u] 代码如下:
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;     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部