E
E
Eugene Chefranov2018-01-17 20:40:09
Visual Basic
Eugene Chefranov, 2018-01-17 20:40:09

How to save an image in higher resolution?

I draw an image in a PictureBox which is 365x292px in size, and when I save the image from the PictureBox, the image naturally has the same resolution. Many items are drawn in a PictureBox and the coordinates are fixed, not relative to the PictureBox sizes. I don't want to change all the values ​​manually.
How can you save an image at a higher resolution, like twice the size?
The code can be given in VB.NET or C#. The languages ​​are similar, I think it will not be difficult to apply the code
. I draw something like this:

Dim BM As New Bitmap(PictureBox1.Width, PictureBox1.Height, Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim g As System.Drawing.Graphics = Graphics.FromImage(BM)

g.DrawLine(pen3, X1, Y1 * 2 - 50, X2, Y2 * 2 - 50)
g.DrawLine(pen3, X1, Y1 * 2 - 50, X3, Y3 * 2 - 50)
g.DrawLine(pen3, X2, Y2 * 2 - 50, X3, Y3 * 2 - 50)

PictureBox1.Image = BM

This is not the whole code, but a part, as an example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitriyq, 2018-01-17
@Dmitriyq

Hello, in c#:

Image srcImage = pictureBox.Image;

RectangleF rectangleDest = new RectangleF(0, 0, srcImage.Width * 2, srcImage.Height * 2); // тут масштаб х2
RectangleF rectangleSource = new RectangleF(0, 0, srcImage.Width, srcImage.Height);

Bitmap destBitmap = new Bitmap(Convert.ToInt32(rectangleDest.Width), Convert.ToInt32(rectangleDest.Height));
Graphics graphics = Graphics.FromImage(destBitmap);

graphics.DrawImage(srcImage, rectangleDest, rectangleSource, GraphicsUnit.Pixel);
graphics.Save();

destBitmap.Save("resizable.png");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question