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#利用FluentFTP實(shí)現(xiàn)FTP上傳下載功能詳解
FTP作為日常工作學(xué)習(xí)中,非常重要的一個(gè)文件傳輸存儲(chǔ)空間,想必大家都非常的熟悉了,那么如何快速的實(shí)現(xiàn)文件的上傳下載功能呢,本文以一個(gè)簡單的小例子,簡述如何通過FluentFTP實(shí)現(xiàn)文件的上傳和下載功能2023-02-02C#基于TCP實(shí)現(xiàn)簡單游戲客戶端的完整實(shí)例
這篇文章主要給大家介紹了關(guān)于C#基于TCP實(shí)現(xiàn)簡單游戲客戶端的相關(guān)資料,通過本文介紹的方法可以直接實(shí)現(xiàn)游戲客戶端,是個(gè)非常適合學(xué)習(xí)的實(shí)例需要的朋友可以參考下2021-11-11C#郵件定時(shí)群發(fā)工具Atilia用法實(shí)例
這篇文章主要介紹了C#郵件定時(shí)群發(fā)工具Atilia用法,較為詳細(xì)的分析了Atilia實(shí)現(xiàn)郵件定時(shí)群發(fā)功能的原理與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法
這篇文章主要介紹了C#實(shí)現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法,涉及C#創(chuàng)建縮略圖的相關(guān)圖片操作技巧,需要的朋友可以參考下2015-06-06解析錯(cuò)誤富文本json字符串(帶雙引號(hào))的快速解決方法
下面小編就為大家?guī)硪黄馕鲥e(cuò)誤富文本json字符串(帶雙引號(hào))的快速解決方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08c# 使用谷歌身份驗(yàn)證GoogleAuthenticator的示例
這篇文章主要介紹了c# 使用谷歌身份驗(yàn)證GoogleAuthenticator的示例,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01