Question Modifying an image and Saving it

Diamond Star

New member
Joined
Jul 5, 2016
Messages
3
Programming Experience
3-5
Hello ! I want to load an image from file then modify it with Graphics object methods like rotating and scaling. I managed to load image and sscaling it and drawing it on form, but how to save it with the modifications? That what I want to know. Brifly, How to create a graphics object from image and scaling or rotating it then saving it to a file?
 
Creating an Image object, drawing on it and then saving it is no big deal. You just need to call Graphics.FromImage and then Image.Save. Rotating can be done using the Image.RotateFlip method, as long as it's just by multiples of 90 degrees. Note that you must create a new Graphics object to draw on an Image after calling RotateFlip. If you want anything more than that then you will actually have to create a new Bitmap object of the appropriate dimensions and then draw the original Image onto that in the appropriate manner. Once you've disposed the original Image, you can save the new Image to the same location.
 
Thanks!
But I tried it. I used Graphics.FromImage then I scaled it and drew it on the form successfully.
but when I used Image.Save the image saved with no scaling.
Anyway, I will retry it and if I failed again I will post the code I use.
 
Thanks!
But I tried it. I used Graphics.FromImage then I scaled it and drew it on the form successfully.
but when I used Image.Save the image saved with no scaling.
Anyway, I will retry it and if I failed again I will post the code I use.

Of course the Image saved with no scaling. Did you read what I posted? I said that you need to create a new Bitmap, draw the original Image onto that with scaling and then save the new Bitmap. Drawing an Image onto a form with scaling has exactly zero effect on the Image you draw. It only has an effect on what you draw on, which is exactly why you need a Bitmap to draw on and then save.
 
Back
Top