| 分類:[C#]
VisualBasic2005、C#を利用しています。
画像A、画像B、画像Cと3枚の同じ大きさの画像があるのですが。
画像Aの輝度値が低いピクセルから順番にそのピクセルの”場所”を取得して、 Bの画像の同じ”場所”にある”色”をGetPixelで取得し、画像CにSetPixelで”色”をその”場所”に置いていきたいのですが 処理がものすごく遅くて、どうにか早くする方法はないでしょうか。 よろしくお願いいたします。 namespace テスト { public partial class Form1 : Form { Bitmap effe = new Bitmap(@"画像A.bmp"); Bitmap mat = new Bitmap(@"画像B.png"); Bitmap base1 = new Bitmap(@"画像C.png"); Rectangle rect, rect2;
public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } protected override void OnPaint(PaintEventArgs e)//描画する所 { base.OnPaint(e); rect = new Rectangle(0,0,mat.Size.Width,mat.Size.Height); e.DrawImage(base1,rect); }
//四捨五入 public static double ToHalfAdjust(double dValue, int iDigits) { double dCoef = System.Math.Pow(10, iDigits);
return dValue > 0 ? System.Math.Floor((dValue * dCoef) + 0.5) / dCoef : System.Math.Ceiling((dValue * dCoef) - 0.5) / dCoef; }
private void SetPixcel() { int w = effe.Size.Width; int h = effe.Size.Height; for (int s = 0; s <= 50; s++) { for (int a = 0; a < w; a++) { for (int b = 0; b < h; b++) { double h1 = ToHalfAdjust(effe.GetPixel(a, b).GetBrightness(), 1) * 50;
if (h1 == s) { int P = mat.GetPixel(a,b).ToArgb(); base1.SetPixel(a, b, Color.FromArgb(P)); Application.DoEvents(); } } } Invalidate(); } } private void button1_Click(object sender, EventArgs e) { SetPixcel(); } } } |