Created
November 7, 2019 14:56
-
-
Save ImagingSolution/129ea5a2b3f056274c03116acff7a16b 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 NegativeImage5(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; | |
Parallel.For(0, height, y => | |
{ | |
// 行の先頭ポインタ | |
byte* pLine = ptr + y * stride; | |
for (int x = 0; x < width; x++) | |
{ | |
// 輝度値の取得 | |
byte r = pLine[2]; | |
byte g = pLine[1]; | |
byte b = pLine[0]; | |
// 輝度値の設定 | |
pLine[2] = (byte)(255 - r); | |
pLine[1] = (byte)(255 - g); | |
pLine[0] = (byte)(255 - b); | |
// 次の画素へ | |
pLine += 3; | |
} | |
} | |
); | |
} | |
// アンロック | |
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/