|
2009/04/28(Tue) 16:31:52 編集(投稿者) 2009/04/28(Tue) 16:31:47 編集(投稿者)
余計な処理は除いてますが、以下コードです。現象は再現します。
using System; using System.IO; using System.Drawing; using System.Windows.Forms; using System.Drawing.Imaging;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { int x = 0; int y = 0; int posx = 0; int posy = 0; Bitmap bmp;
public Form1() { InitializeComponent();
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
bmp = (Bitmap)Image.FromStream(File.OpenRead(@"c:\test.jpg"), false, false); //←@の読込処理です。 ConvFile(); //←Aの画像処理です。ここをコメント化するかしないかで描画速度が変わります。 }
public void ConvFile() { BitmapData d = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int residual = d.Stride - d.Width * 3;
unsafe { byte* p = (byte*)(void*)d.Scan0; for (int y = 0; y < d.Height; ++y) { for (int x = 0; x < d.Width; ++x) { p[2] += 0; //実際は計算値を代入しています p[1] += 0; p[0] += 0; p += 3; } p += residual; } }
bmp.UnlockBits(d); }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(bmp, x, y, bmp.Width, bmp.Height); }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { posx = e.X; posy = e.Y; }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) return;
x -= posx - e.X; y -= posy - e.Y;
pictureBox1.Invalidate();
posx = e.X; posy = e.Y; } } }
|