C# Bitmap 复制
2013-10-17 13:26
309 查看
以后再详述,先上代码。
public bool CopyBitmap(Bitmap source, Bitmap destination) { if ((source.Width != destination.Width) || (source.Height != destination.Height) || (source.PixelFormat != destination.PixelFormat)) { return false; } int bitdepth_per_pixel = Bitmap.GetPixelFormatSize(source.PixelFormat) / 8; if (bitdepth_per_pixel != 1 && bitdepth_per_pixel != 3 && bitdepth_per_pixel != 4) { return false; } 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); int source_bitmapdata_bitdepth_width = source_bitmapdata.Width * bitdepth_per_pixel; int source_bitmapdata_height = source_bitmapdata.Height; int source_bitmapdata_bitdepth_stride = source_bitmapdata.Stride; unsafe { byte* source_ptr = (byte*)source_bitmapdata.Scan0; byte* destination_ptr = (byte*)destination_bitmapdata.Scan0; int offset = source_bitmapdata_bitdepth_stride - source_bitmapdata_bitdepth_width; for (int i = 0; i < source_bitmapdata_height; i++) { for (int j = 0; j < source_bitmapdata_bitdepth_width; j++, source_ptr++, destination_ptr++) { *destination_ptr = *source_ptr; } source_ptr += offset; destination_ptr += offset; } } source.UnlockBits(source_bitmapdata); destination.UnlockBits(destination_bitmapdata); return true; } catch { return false; } }
相关文章推荐
- C# Bitmap 复制的小例子
- C#复制文件夹,删除文件夹的方法
- C#判断文件是复制还是剪切
- Bitmap的复制和注意
- 病毒及流氓软件自我复制的简单实现(C#)
- 病毒及流氓软件自我复制的简单实现(C#)
- C# 复制,粘贴文本
- C#开发日志[2013-12-5]创建Bitmap引发"参数无效"异常
- c# 复制文件夹
- C# 复制 粘贴 剪切 撤销
- C#文件操作源码 递归复制一个目录 递归删除文件 和 文件夹
- C# 对文件与文件夹的操作 -- 删除、移动与复制
- C# 深复制
- C#复制文件夹
- C#复制文件夹的文件到另一个文件夹
- C# 复制和克隆认识浅谈2
- (原创)c#学习笔记09--定义类08--浅度和深度复制
- c# 复制文件后新的文件变成只读文件
- C#实现各种格式文件的复制
- C# 下实现把Array复制到ArrayList中的四种方法