Created
November 7, 2019 14:55
-
-
Save ImagingSolution/9cb61d5df0b51fce829e722ab8b5f3d3 to your computer and use it in GitHub Desktop.
【C#】画像の輝度値の取得設定速度の比較
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// usafeのポインタを使って輝度値の取得設定 | |
/// </summary> | |
/// <param name="bmp"></param> | |
private void NegativeImage4(Bitmap bmp) | |
{ | |
var width = bmp.Width; | |
var height = bmp.Height; | |
// Bitmapをロック | |
var bmpData = bmp.LockBits( | |
new Rectangle(0, 0, width, height), | |
System.Drawing.Imaging.ImageLockMode.ReadWrite, | |
bmp.PixelFormat | |
); | |
// メモリの幅のバイト数を取得 | |
var stride = Math.Abs(bmpData.Stride); | |
unsafe | |
{ | |
// 画像データ格納用配列 | |
var ptr = (byte*)bmpData.Scan0; | |
byte r, g, b; | |
byte* pLine = ptr; | |
for (int y = 0; y < height; y++) | |
{ | |
// 行の先頭ポインタ | |
ptr = pLine; | |
for (int x = 0; x < width; x++) | |
{ | |
// 輝度値の取得 | |
r = ptr[2]; | |
g = ptr[1]; | |
b = ptr[0]; | |
// 輝度値の設定 | |
ptr[2] = (byte)(255 - r); | |
ptr[1] = (byte)(255 - g); | |
ptr[0] = (byte)(255 - b); | |
// 次の画素へ | |
ptr += 3; | |
} | |
// 次のラインへ | |
pLine += stride; | |
} | |
} | |
// アンロック | |
bmp.UnlockBits(bmpData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
【C#】画像の輝度値の取得設定速度の比較
https://imagingsolution.net/program/set_get_bright_speed/