PDA

View Full Version : Solved: Rotating pictures



mdmackillop
02-17-2006, 06:45 AM
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

XLGibbs
02-17-2006, 02:39 PM
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..

mdmackillop
02-17-2006, 02:59 PM
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.

XLGibbs
02-17-2006, 05:09 PM
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.

johnske
02-17-2006, 05:24 PM
Have a look at PhotoEd (is on Office 2000, don't know if discontinued) it's quick and easy to rotate...

XLGibbs
02-17-2006, 05:49 PM
Cool. Thanks Johnske . (I had hoped someone much smarter would tell me where to find the reference I needed): pray2: :clap:

mdmackillop
02-17-2006, 06:00 PM
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.

johnske
02-18-2006, 01:59 AM
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 :devil: ... now that I've said this someone will come along and post some code just to disprove what was said above :rofl:

Regards,
John :)

Ivan F Moala
02-18-2006, 05:09 AM
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.

Rembo
02-18-2006, 06:22 AM
Hello Malcolm,


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 (http://www.gogowishs.com/products/pictureviewer/) or GdPicture (http://www.gdpicture.com/) (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 (http://www.irfanview.com/) and that was a piece of cake.

All it took was this routine to get it done:

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

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

jolivanes
02-19-2006, 12:43 AM
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)


Selection.ShapeRange.IncrementRotation Range("D1").Value


Regards.
John

mdmackillop
02-19-2006, 06:38 AM
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.php?p=57914&postcount=17

Regards
Malcolm

Rembo
02-19-2006, 03:11 PM
Hello John,


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.

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

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 (http://perso.wanadoo.fr/pierre.g/xnview/engfl.html) (from XnView)
FreeImage (http://freeimage.sourceforge.net/) (VBA wrapper available)

Enough material to chew on http://vbaexpress.com/forum/images/smilies/001.gif

Rembo

Rembo
02-20-2006, 01:45 AM
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



The application is posted here.
http://vbaexpress.com/forum/showpost.php?p=57914&postcount=17

mdmackillop
02-20-2006, 02:42 AM
Thanks Rembo,
I've put this in for KB scrutiny but I'm happy to receive any further comments here.
Regards
Malcolm

jolivanes
02-20-2006, 03:24 AM
Thanks Rembo.

Indeed, gives me something to do.
Groetjes from Canada