C#實現(xiàn)圖片放大功能的按照像素放大圖像方法
本文實例講述了基于Visual C#實現(xiàn)的圖片放大功能代碼??梢灾苯臃糯笙袼兀愃苝hotoshop的圖片放大功能,可用于像素的定位及修改,由于使用了指針需要勾選允許不安全代碼選項,讀者可將其用于自己的項目中!
關(guān)于幾個參數(shù)說明:
srcbitmap源圖片
multiple圖像放大倍數(shù)
放大處理后的圖片
注意:需要在頭部引用:using System.Drawing;using System.Drawing.Imaging;
至于命名空間讀者可以自己定義。
主要功能代碼如下:
using System.Drawing;using System.Drawing.Imaging;
public Bitmap Magnifier(Bitmap srcbitmap, int multiple)
{
if (multiple <= 0) { multiple = 0; return srcbitmap; }
Bitmap bitmap = new Bitmap(srcbitmap.Size.Width * multiple, srcbitmap.Size.Height * multiple);
BitmapData srcbitmapdata = srcbitmap.LockBits(new Rectangle(new Point(0, 0), srcbitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData bitmapdata = bitmap.LockBits(new Rectangle(new Point(0, 0), bitmap.Size), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
byte* srcbyte = (byte*)(srcbitmapdata.Scan0.ToPointer());
byte* sourcebyte = (byte*)(bitmapdata.Scan0.ToPointer());
for (int y = 0; y < bitmapdata.Height; y++)
{
for (int x = 0; x < bitmapdata.Width; x++)
{
long index = (x / multiple) * 4 + (y / multiple) * srcbitmapdata.Stride;
sourcebyte[0] = srcbyte[index];
sourcebyte[1] = srcbyte[index + 1];
sourcebyte[2] = srcbyte[index + 2];
sourcebyte[3] = srcbyte[index + 3];
sourcebyte += 4;
}
}
}
srcbitmap.UnlockBits(srcbitmapdata);
bitmap.UnlockBits(bitmapdata);
return bitmap;
}
相關(guān)文章
C# 操作PostgreSQL 數(shù)據(jù)庫的示例代碼
本篇文章主要介紹了C# 操作PostgreSQL 數(shù)據(jù)庫的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
C#從windows剪貼板獲取并顯示文本內(nèi)容的方法
這篇文章主要介紹了C#從windows剪貼板獲取并顯示文本內(nèi)容的方法,涉及C#操作剪貼板的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
C# Dictionary和SortedDictionary的簡介
今天小編就為大家分享一篇關(guān)于C# Dictionary和SortedDictionary的簡介,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10
C#基礎(chǔ)學(xué)習(xí)系列之Attribute和反射詳解
大家在使用Attribute的時候大多需要用到反射,所以放在一起。下面這篇文章主要給大家介紹了關(guān)于C#基礎(chǔ)學(xué)習(xí)系列之Attribute和反射的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09
WPF 在image控件用鼠標(biāo)拖拽出矩形的實現(xiàn)方法
這篇文章主要介紹了WPF 在image控件用鼠標(biāo)拖拽出矩形的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Unity3D實現(xiàn)待機(jī)狀態(tài)圖片循環(huán)淡入淡出
這篇文章主要為大家詳細(xì)介紹了Unity3D實現(xiàn)待機(jī)狀態(tài)圖片循環(huán)淡入淡出,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04

