Tomasi
Tomasi

Reputation: 2509

Other ways to resize image than Graphics.DrawImage

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?

Upvotes: 1

Views: 1057

Answers (4)

Navid Farhadi
Navid Farhadi

Reputation: 3467

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(...);

Upvotes: 1

Edgar Hernandez
Edgar Hernandez

Reputation: 4030

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.

Upvotes: 2

Jason Kresowaty
Jason Kresowaty

Reputation: 16520

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.

Upvotes: 0

Vlad
Vlad

Reputation: 35594

You can put Image into a ViewBox.

See http://www.wpftutorial.net/ViewBox.html

Upvotes: 0

Related Questions