currently I'm programming some sort of displaying measurement results.
So I drew nearly 30thousand dots on a pciturebox. A little bit slow but it works.
Here's my problem: When painting is done and i drag a windows window over this painting
the image starts to recreatet(reload) itself.
Things I did so far:
I painted everything on a bitmap file that is later on the picturebox with
| grafik.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height); |
I also tried to set the image of the picturebox to the bitmap.
But it results in a heavy laggy loop and doesn't solve my problem.
I set a bool that says me the image is already drawn but if I
drag a window over the image it gets just erased and due to
my bool not repainted
I want it like it is the picturebox's image then it would never reload...
I hope you understood my problem. If not, pls feel free to ask me.
I attached my code. Thanks and best regarts.
FroglegPosted Feb 21, 2011, 7:35 AM
Bitmap myBmp;
private void Form1_Load(object sender, EventArgs e){
pictureBox1.Image = createBmp();
}
public Bitmap createBmp()
{
//draw your bitmap
myBmp = new Bitmap(pictureBox1.Width,pictureBox1.Height);
Graphics g = Graphics.FromImage(myBmp);
g.FillRectangle(Brushes.Blue,0,0,pictureBox1.Width, pictureBox1.Height);
return myBmp;
}
you don't need code in picturebox paint event
Even if you load a jpg from your hdd it still needs to be loaded into memory to be accessed - the only advantage being form will load faster
Sascha BPosted Feb 23, 2011, 8:56 AM
I made it like this:
public void paintpicture(int tabnummer)
{
int w = 390 - 1, h = 390 - 1;
Bitmap bitmap = new Bitmap(w,h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics bmpgrafik = Graphics.FromImage(bitmap);
bmpgrafik.CompositingMode = CompositingMode.SourceCopy;
bmpgrafik.CompositingQuality = CompositingQuality.HighQuality;
try{
bmpgrafik.FillRectangle(new SolidBrush(notenfarbe), x + w / 2 - dotstrength, y * -1 + h / 2 - dotstrength, dotstrength * 2 + 1, dotstrength * 2 + 1);
}catch(Exception error)
{
;
}
imagepreview[tabnummer].Image = bitmap;
bitmap.Dispose();
bmpgrafik.Dispose();
}
It only shows a red cross. I searched and google says that it could be a paint exception.
But it never throws out an exception...
If I made it in the paint event with
grafik.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height);
Where grafik is Graphics grafik = e.Graphics
instead of imagepreview[tabnummer].Image = bitmap;
it works normal
I really want it working. Have you an other idea?
Thanks
Edit: Something that work too is to save the bitmap first into a file and the load it with Image.FromFile(filename);
But thats not really optimal...
Solution: Sorry that I said your tipp didn't work.
I was just that stupid and disposed the bitmap directly after setting it up :D
So the code above works perfectly if you leave out bitmap.dispose();
Sascha BPosted Feb 21, 2011, 9:01 AM
Sascha BPosted Feb 21, 2011, 4:29 AM
FroglegPosted Feb 18, 2011, 3:22 PM