Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Imaging for Windows automation

Status
Not open for further replies.

glab

Programmer
Jun 21, 2000
19
0
0
US
Hi everyone!

I have a question for you.
OK. Here goes.

I'm writing a utility which will go through all pages in a multi-page TIFF image in order to find landscaped pages, rotate them to make them portrait and save the image. There could be multiple TIFF images, so I need to perform batch operation within specified directory; and number of pages in TIFF images could be anywhere from 1 to several thousands.

So I'm trying to use Image Admin and Image Edit controls available with VB. In order to be able to edit image I have to use Display method of Image Edit control, so every page which got displayed gets rotated. The problem is that as soon as I display next page all changes made to the previous one are discarded. So when I save the file, apparently only the last page gets to keep changes.
Here's a piece of code, that I've come up with to overcome this problem.


Private Sub cmdRotate_Click()

Dim h, w, pc, i

ImgEdit1.Image = "C:\Temp\1.tif"
pc = ImgEdit1.PageCount

For i = 1 To pc
ImgEdit1.Page = i
ImgEdit1.Display
h = ImgEdit1.ImageHeight
w = ImgEdit1.ImageWidth
If w > h Then
ImgEdit1.RotateLeft
End If
ImgEdit1.Save
h = 0
w = 0
Next

MsgBox "Done!!!"

End Sub


But the other problem is - it's very slow. Let's say third-party application rotates 1000-page TIFF image - 130 MB - in 5 minutes, while the same image gets processed with my code in about one hour. I know why it's slow. What I didn't figure out yet is how to make it faster.
Could you advise me as to what approach is better to use to make it work?

Thank you.
 

Let me take a guess... you are doing this over a network, right?

Copy the file locally do your work and copy it back across. This will be much faster.

(If not let us know I have some code around here somewhere.)

Good Luck

 
Hi vb5prgrmr,

First of all, thanks for your reply.
Secondly, no, I'm doing it locally and it kills me even thinking, that eventually I'll need to do it over the network. And I'm talking about batch processing of potentially tens of images of 100+ MB and 1000+ pages in each one.

So any help, please, a hint, a tip, a pointer.

Thanks again.
 

Ok, here are some simple coding tips for you...

your code...
[tt]
Private Sub cmdRotate_Click()

Dim h, w, pc, i

ImgEdit1.Image = "C:\Temp\1.tif"
pc = ImgEdit1.PageCount

For i = 1 To pc
ImgEdit1.Page = i
ImgEdit1.Display
h = ImgEdit1.ImageHeight
w = ImgEdit1.ImageWidth
If w > h Then
ImgEdit1.RotateLeft
End If
ImgEdit1.Save
h = 0
w = 0
Next

MsgBox "Done!!!"

End Sub
[/tt]

faster code

[tt]
Private Sub cmdRotate_Click()

Dim I As Long

ImgEdit1.Image = "C:\Temp\1.tif"

For I = 1 To ImgEdit1.PageCount
ImgEdit1.Page = i
ImgEdit1.Display
If ImgEdit1.ImageWidth > ImgEdit1.ImageHeight Then
ImgEdit1.RotateLeft
ImgEdit1.Save False
End If
Next

MsgBox "Done!!!"

End Sub
[/tt]

Why is this faster, you may ask? Let me explain...

First you variables are variants which take extra cycles for their actual type to be determined.

Next the PageCount is not retrieved into a variable and then evaluated for the For loop (save a couple of cycles there)

Then the width and height values are not retrieved into variables and then evaluated and then reset they are evaluated directly.

And finally it is only saved IF the page has been rotated (A BIG SAVINGS in cycles and in I/O or writting to disk, which is the slowest of your activities in this operation).

Oh yeah, maybe a couple of cycles are saved by telling it when it is to save, that it is to use its origional zoom factor.

Give it a test and see and when you start doing it across the network ... copy them locally before you do your operations on them! You will save network traffic and processing time.

Good Luck

 
vb5prgrmr,

I'm not sure if you'll look at this post again, but I just want to believe that you would and I want to tell you that it was very helpful. I'll give it a try.

Thanks a lot.
 

Certainly... After you run your tests tell me how much faster it is (if it is any).

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top