C# Bitmap 復(fù)制的小例子
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;
}
}
相關(guān)文章
C#中LINQ?to?DataSet操作及DataTable與LINQ相互轉(zhuǎn)換
這篇文章介紹了C#中LINQ?to?DataSet操作及DataTable與LINQ相互轉(zhuǎn)換,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05Datagridview使用技巧(9)Datagridview的右鍵菜單
這篇文章主要為大家詳細(xì)介紹了Datagridview使用技巧,Datagridview的右鍵菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式
本篇文章主要介紹了詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04