手机
当前位置:查字典教程网 >编程开发 >C#教程 >C# Bitmap 复制的小例子
C# Bitmap 复制的小例子
摘要:复制代码代码如下:publicBitmapCopyBitmap(Bitmapsource){intdepth=Bitmap.GetPixel...

复制代码 代码如下:

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# Bitmap 复制的小例子】相关文章:

C#简单获取时间差的小例子

c# 接口interface基础入门小例子

C# 合并GriewView相同列的小例子

C# Linq读取XML文件的实例

c# 开机启动项的小例子

C# 实现简单打印的实例代码

C# 图片剪切与缩小的实例

c# 匿名方法的小例子

c# 关闭窗体时提示的小例子

C#之IP地址和整数互转的小例子

精品推荐
分类导航