Don't ask me why but i can't use this method because I need to create 2 image objects to make it work.
I want to be able to resize a single Image object without needing to create another one. Is this possible and how?
Don't ask me why but i can't use this method because I need to create 2 image objects to make it work.
I want to be able to resize a single Image object without needing to create another one. Is this possible and how?
No, this is not possible. The height and width of an Image
object are fixed at the time the Image
object is constructed. This limitation exists in the underlying GDI+ API.
If you do not need to modify the Image
, perhaps it is acceptable to scale it every time it is rendered. For example, in a Control.Paint
event, you can use Graphics.DrawImage
to render it directly onto the PaintEventArgs.Graphics
context. This will allow you to draw the image at different sizes without creating additional Image
objects.
If your reason is a problem of Memory or something like that (very large image). You could try to open it and resize it using Aforge.
You can use Matrix
to resize image. you must create a matrix and scale it and set it to your Graphics
object.
Matrix mx = new Matrix();
mx.Scale(2.0f,2.0f);
graphics.Transform=mx;
graphics.DrawImage(...);