Consulting

Results 1 to 16 of 16

Thread: Solved: Rotating pictures

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Rotating pictures

    Hi all,
    I can rotate a picture within the Filmstrip display in My Computer. Can this be done from Excel. I'm looking to display photographs by selecting the file name from a cell (already solved), and would like the facility to correct the orientation.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Malcolm

    I believe you can rotate shapes in excel. Let me investigate some as to certain methods available, but if the picture preview can be inserted in as a shape, i think the there are ways to spin it..

    Wiil follow up once I get some checking done on the issue..
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Pete,
    I was reaaly wanting the file to be saved with the correct orientation. We handle quite a few photos at work, and this utility would be useful. I'm guessing it's one of these API things.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    MD,

    No luck. I was able to load a picture into a form which obviously is no problem, but I could not get the picture into any object that allowed for free rotation (similar to the WordArt shapes...)

    Reviewing some object models, it appears what may be necessary is an external app to manage this process for you as the Picturebox methods available in Java, VB6, C# appear to have ready access to such capability. I was unsuccessful in setting references to any library that would allow similar control of an object embedded in excel, and I couldnt find a control equivalent to the Windows picture box (the one used in post XP Picture and Fax viewer).

    A VB App could contain all the elements you need, and probably would not be all that difficult if you want me to whip something together over the long weekend..I don't have my daughter so I will be looking for some mind occupying exercises.
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  5. #5
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Have a look at PhotoEd (is on Office 2000, don't know if discontinued) it's quick and easy to rotate...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  6. #6
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Cool. Thanks Johnske . (I had hoped someone much smarter would tell me where to find the reference I needed)
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Our usual practice is to scan through the picures in Filmstrip and sort them there. It just seemed tidier to have that facility when photos were being renamed etc. It's not a critical item so I wouldn't spend much time on research, unless you have any further use for the procedure.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Malcolm,

    Did a web search and it appears the only way to rotate pictures in excel is by using another app (such as PhotoEd). i.e. you rotate the pix before importing them to excel - or else - export, rotate, and re-import.

    Of course you know what'll happen next dontcha ... now that I've said this someone will come along and post some code just to disprove what was said above

    Regards,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  9. #9
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    You can rotate images on sheets in XL 2003.

    If you needed to rotate in a form then you would need an ActiveX control that could facilitate this OR use API's.
    Kind Regards,
    Ivan F Moala From the City of Sails

  10. #10
    Hello Malcolm,

    Quote Originally Posted by mdmackillop
    I can rotate a picture within the Filmstrip display in My Computer. Can this be done from Excel. I'm looking to display photographs by selecting the file name from a cell (already solved), and would like the facility to correct the orientation.
    I see three options to achieve this:

    1) You use some sort of API call.
    2) You install an ActiveX component that allows you to manipulate images. For example you could buy one at GoGoWishs or GdPicture (under the download section they offer a free license for the older version)
    3) You take the easy route by downloading a free utility that allows command processing. I just tried to do it with IrfanView and that was a piece of cake.

    All it took was this routine to get it done:

    [VBA]Sub RotateImage()

    ' Copy your image to the clipboard here

    ' Have Irfan view rotate your image
    Call Shell("D:\Grafisch\Irfan\i_view32.exe /clippaste /rotate_l /clipcopy /killmesoftly", 1)

    ' And paste it back into your worksheet
    End Sub[/VBA]

    If you install IrfanView you will find the file i_options.txt in the installation directory that lists all the command arguments.

    Good luck,

    Rembo

  11. #11
    Rembo.
    How do you incrementally rotate with IrfanView? I tried changing "rotate_l" all different ways but no luck.
    I rotate pictures with the following (Picture has to be selected and degrees of turn required in cell D1)

    [VBA]
    Selection.ShapeRange.IncrementRotation Range("D1").Value
    [/VBA]

    Regards.
    John

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks to all who replied. A few things to look at for the future.

    Rembo,
    Thanks for the links. I've set IrfanView to work exactly as I planned, rotating and saving the file with its new orientation, so I won't go for an API solution just now, (I'll leave that to someone else to solve). The application is posted here.
    http://vbaexpress.com/forum/showpost...4&postcount=17

    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    Hello John,

    Quote Originally Posted by jolivanes
    How do you incrementally rotate with IrfanView? I tried changing "rotate_l" all different ways but no luck.
    There is a custom rotation available in the program itself. I think you will have to install a plugin though to get that function.

    As far as I know there is no command line option to rotate an image a certain amount of degrees. However, you could control the IrfanView application to a certain extend. Not exactly an ideal solution but it would work all the same. In theorie the method below will pretty much work with every graphics editor, you simply activate menu options using the SendKeys command.

    Important to know is that the SendKeys command is in essence one-way-traffic; it will send keystrokes blindly but it doesn't know if the keystrokes arrive in the right place. It's also easily disrupted so use with caution.

    [VBA]Sub RotateImage_nr_degrees(dblDegRotation As Double)

    'Copy your image to the clipboard here

    'Have Irfan view rotate your image
    Dim AppID As Double
    AppID = Shell("C:\YourDir\i_view32.exe /clippaste", 4)

    'Activate IrfanView
    AppActivate AppID

    Application.Wait (Now + TimeValue("0:00:01"))
    'Send commands for rotation to IrfanView
    'Open Custom Rotation (note that ^U doesn't work)
    SendKeys "%I", True
    SendKeys "{DOWN 5}", True
    SendKeys "~", True

    'Enter the degrees to rotate
    SendKeys CStr(dblDegRotation), True

    'Give two tabs to move to OK button and enter
    SendKeys "{TAB 2}", True
    SendKeys "~", True

    'Copy image to the clipboard
    SendKeys "%E", True
    SendKeys "{UP 4}", True
    SendKeys "~", True

    'And exit IrfanView
    SendKeys "{ESC}", True

    ' Paste rotated image back into your worksheet here
    End Sub[/VBA]

    A more solid solution is to use an object model that can be manipuated from VBA, as sort of mentioned in my previous post. In addition to the links in my previous post you might want to check out these sites as well:

    GFL SDK (from XnView)
    FreeImage (VBA wrapper available)

    Enough material to chew on

    Rembo

  14. #14
    Hi Malcolm,

    That is some neat coding, I picked up a few things from your workbook, thanks. Looking at the routine 'Rotate' I noticed two things. Certainly no biggies but I thought I'd mention them anyway.

    You declared a variable Cek As String but you don't use it (anymore). You might as well ditch it.

    As per my example the second argument of the Shell command is 1. If you set it to 0 then the IrfanView window is hidden but it still receives focus. If you are experiencing some screen flickering then you might want to try set it to 0.

    Cheers,

    Rembo


    Quote Originally Posted by mdmackillop

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Rembo,
    I've put this in for KB scrutiny but I'm happy to receive any further comments here.
    Regards
    Malcolm
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    Thanks Rembo.

    Indeed, gives me something to do.
    Groetjes from Canada

Posting Permissions

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