C# Bitmap 复制的小例子
时间:2023-01-19 12:49:39
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;
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c#实现KTV点歌系统
![](https://img.aspxhome.com/file/2023/9/100199_0s.png)
Android实现中国象棋游戏(局域网版)
![](https://img.aspxhome.com/file/2023/7/126687_0s.jpg)
Android语音声波控件 Android条形波控件
C++ 让函数返回数组的方法
基于Java实现的图的广度优先遍历算法
解决idea web项目中out目录更新不同步问题
![](https://img.aspxhome.com/file/2023/3/97813_0s.png)
c++动态内存管理详解(new/delete)
![](https://img.aspxhome.com/file/2023/0/122570_0s.png)
谈谈RxJava2中的异常及处理方法
详解Mybatis通用Mapper介绍与使用
Java特性之注解和异常 Throwable
![](https://img.aspxhome.com/file/2023/4/82994_0s.png)
Struts和servlet不能共存问题解决方法
一篇文章让你彻底了解Java可重入锁和不可重入锁
![](https://img.aspxhome.com/file/2023/1/125491_0s.png)
java ThreadGroup的作用及方法详解
![](https://img.aspxhome.com/file/2023/2/60762_0s.jpg)
Java数据结构之优先级队列(堆)图文详解
![](https://img.aspxhome.com/file/2023/2/68022_0s.png)
Treeview动态添加用户控件传值和取值的实例代码
![](https://img.aspxhome.com/file/2023/5/102245_0s.jpg)