Forcing PictureBox to save image if image was drawn using code in vb.net

My pictures are sometimes cleared of all drawings when they are taken, creating an image, and sometimes half. Calling GC.Collect () before starting the drawing allows it to draw MORE before clearing it, but how can I stop it completely clearing?

This is in vb.net

Thanks!

+3
source share
2 answers

An easy way to save images in .Net is to make a drawing on a separate Bitmap object, and then set the ImageBox Image property to Bitmap, for example:

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
    // draw whatever
}
pictureBox1.Image = bmp;

Sorry, this is C #, but it should illustrate the OK principle.

- PaintBox Paint, , , ( , ..)..). ( Image ) .

+1

, "bmp" "g" , . , . bmp.clone, , , bmp , . ( ) , .

Dim bm As New Bitmap("C:\picture.bmp")
Dim thumb As New Bitmap(42, 30)
Dim g As Graphics = Graphics.FromImage(thumb)

g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bm, New Rectangle(0, 0, 42, 30), New Rectangle(0, 0, bm.Width, _bm.Height), GraphicsUnit.Pixel)
pbxHead.Image = thumb.Clone()

g.Dispose()
bm.Dispose()
thumb.Dispose()
0

Source: https://habr.com/ru/post/1719475/


All Articles