Results 1 to 5 of 5

Thread: Modifying an image and Saving it

  1. #1
    Diamond Star is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2016
    Posts
    3
    Reputation
    0

    Modifying an image and Saving it

    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?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,813
    Reputation
    1707
    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.

  3. #3
    Diamond Star is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2016
    Posts
    3
    Reputation
    0
    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.

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,813
    Reputation
    1707
    Quote Originally Posted by Diamond Star View Post
    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.

  5. #5
    Diamond Star is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2016
    Posts
    3
    Reputation
    0
    Ok, Thanks
    I will try it.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •