PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to Image.Save 90 degrees rotated.-VBForums
Results 1 to 8 of 8

Thread: How to Image.Save 90 degrees rotated.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    14

    How to Image.Save 90 degrees rotated.

    Hello guys,
    I have a video source streaming to a picture box. Once I click a button a i duplicate that image to a second picture box. I currently save the second picture box image to a file.

    My camera is rotated 90degrees so my picturebox preview is 90' rotated too. Is there a way to rotate this picture box by 90?
    Here is my code below.

    Thanks.

    PHP Code:
    PictureBox2.Image PictureBox1.Image
                PictureBox1
    .Image.Save("C:\" & TextBox7.Text & "-side1.jpg", Imaging.ImageFormat.Jpeg) 

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,755

    Re: How to Image.Save 90 degrees rotated.

    You call the RotateFlip method on the Image object to rotate or flip it. It's still an Image object like any other after that, so you can do anything with it that you can with any other Image.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,321

    Re: How to Image.Save 90 degrees rotated.

    Hi.
    I'm not sure that copying a file to a second picturebox and then save as jpg will maintain the quality of the image.
    Again this is not 100% sure about a picturebox but when I was manipulating an Image by itself, the default saving was lowering - defaulting the resolution.
    So you may also need to create a graphic object and set the image to it, in order to mess with the InterpolationMode,SmoothingMode and TextRenderingHint
    Slow as hell.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,625

    Re: How to Image.Save 90 degrees rotated.

    vbnet Code:
    1. '
    2.         Dim picRotated As Bitmap = PictureBox1.Image.Clone
    3.  
    4.         'Rotate image clockwise 90 degrees
    5.         picRotated.RotateFlip(RotateFlipType.Rotate90FlipNone)
    6.  
    7.         PictureBox2.Image = picRotated
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,755

    Re: How to Image.Save 90 degrees rotated.

    Quote Originally Posted by sapator View Post
    I'm not sure that copying a file to a second picturebox and then save as jpg will maintain the quality of the image.
    It's worth noting that the code provided doesn't actually copy the Image object. The OP might be under the impression that it does but it's simply displaying the same Image in two PictureBoxes. Because there's only one Image, any changes made to it will be reflected in both PictureBoxes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,321

    Re: How to Image.Save 90 degrees rotated.

    So,Not sure what the OP wants but here is another option,similar to Niya, but avoid a copy paste of the bitmap:

    Code:
     PictureBox2.Image = PictureBox1.Image.Clone     
     PictureBox2.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
    Slow as hell.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,755

    Re: How to Image.Save 90 degrees rotated.

    Quote Originally Posted by sapator View Post
    So,Not sure what the OP wants but here is another option,similar to Niya, but avoid a copy paste of the bitmap:

    Code:
     PictureBox2.Image = PictureBox1.Image.Clone     
     PictureBox2.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
    The only thing that that code avoids compared to Niya's is the declaration of a local variable but the cost of that is displaying the ne Image in the PictureBox before and after rotation rather than just after. I'm not sure whether that might potentially lead to some flicker but it is always good practice to process something before displaying it rather than after.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,321

    Re: How to Image.Save 90 degrees rotated.

    In general I wouldn't use the picturebox so I would use Niya code or better yet manipulating the Image alone and then do whatever with it.
    I just posted a quick alternative so you wouldn't have to to declare a bitmap.

    Picturebox has a clone function but if you want to create a new image, rotate, or even worse, resize , you will get the defaults that may greatly reduce the image quality.
    Especially on the resize, I was struggling quite a lot in order for the image to have the appropriate quality.
    So for example if you have a picturebox and then resize the image, I haven't tried, but I think the quality will get the defaults.I think by default you have a 75% quality on JPEG so the image is already starting to smudge.
    This is the time that you need to take the image out of the picture box, apply the InterpolationMode,Smoothing,Quality etc and get it back to the picturebox or save it to a file.

    OP should explain exactly what he wants and then we can take it from there.
    Slow as hell.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width