C# Bitmap 复制的小例子
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;
}
}
您可能感兴趣的文章:
- C#.NET 剪切板复制粘贴泛型的例子代码参考 Clipboard Copy Paste List
- 一个C#中浅复制(shallow copy)/深复制(deep copy)的例子
- C#.NET 剪切板复制粘贴泛型的例子代码参考 Clipboard Copy Paste List
- Flex中如何利用Bitmap和BitmapData类复制图片到一个TileList控件的例子
- C#、devExpress 的 给bandedGrid加菜单功能 :复制、粘贴的例子
- C#.NET 剪切板复制粘贴泛型的例子代码参考 Clipboard Copy Paste List
- C# Bitmap 复制
- C# 打开多个进度条窗口 ,完成任务后如何自动关闭。比如WIN的复制文件一样。
- C# 远程访问并复制文件
- C#源码学习之---事件经典例子
- c# 关闭窗体时提示的小例子
- c# socket 同步开发小例子
- c#将文件从一个位置复制到另一个位置
- c#项目中遇到的add event 的一个小例子
- C#导出Excel几个例子
- 关于在C#中数组(byte[])复制的两种方式。字节偏移复制与安全复制
- C# 合并GriewView相同列的小例子
- [C#] 筛选复制文件并保持原有的目录结构
- c# 双缓冲 技术与例子
- C#文件流实现文件复制