modifying single frames in a multi frame tiff

S

Steve K.

I would like to rotate pages in a multi-page tiff. Here is my first
attempt:

<code>
public void RotatePageAndSave(int degrees)
{
RotateFlipType rotateType = RotateFlipType.Rotate180FlipNone;
switch(degrees)
{
case 180: rotateType = RotateFlipType.Rotate180FlipNone; break;
case 90: rotateType = RotateFlipType.Rotate90FlipNone; break;
default: throw new Exception("Unsupported rotation value: " +
degrees);
}

// try drawing on the current frame and saving to a temp folder
_attachment.RotateFlip(rotateType);
int y = _attachment.GetFrameCount(FrameDimension.Page);

Console.WriteLine("The saved file should have {0} pages and the " +
"rotating should be on page {1}", _numPages, _currentPageIndex);
_attachment.Save(@"C:\StompTest.tif");
}
 
S

Steve K.

I accidently sent that without finishing, sorry.

What I was *going* to say is that the code below results in a single frame
tif. In fact as soon as I rotate the page, the frame count returned by
GetFrameCount() changes from (whatever it was) to 1. It seems that
perfoming operations on a tif like this invalidates it somehow?

I'm still reading online for various tips and tricks, but not finding too
much about specifically editing a tif like this. The only thing I can think
of would be to pull all the frames out, perform operations, then rebuild the
tif.

Is that what others are doing?

I've run some tests and even that is proving a little more difficult than I
had though. Lots to learn!

-Steve
 
P

Peter Duniho

I accidently sent that without finishing, sorry.

What I was *going* to say is that the code below results in a single
frame
tif. In fact as soon as I rotate the page, the frame count returned by
GetFrameCount() changes from (whatever it was) to 1. It seems that
perfoming operations on a tif like this invalidates it somehow?

Ah. Well, not something I know about first-hand, but that sounds about
right. I'd guess the RotateFlip() method is just a simple helper that
basically creates a new internal image, copying the original into the new
one thereby replacing it.
I'm still reading online for various tips and tricks, but not finding too
much about specifically editing a tif like this. The only thing I can
think
of would be to pull all the frames out, perform operations, then rebuild
the
tif.

Sounds like a reasonable workaround to me. I don't view the .NET
Framework as being a full-featured image editing framework. It has some
basic functionality, but it still leaves lots of things for you to manage
manually. Assuming .NET has a way for you to generate a multi-frame image
(haven't done that myself), that seems like a better way to go.

BTW, if performance is important, you may want to avoid using RotateFlip()
in this case, given that it does generate a brand new image without any
other frames. Using RotateFlip(), you'd have to copy your original Image
so that you don't muck it up with the call to RotateFlip(), and then copy
the rotated image into the new Image you're building.

Instead, you should just use Graphics.FromImage() on the Image you're
building so that you can draw into its current frame, set the Transform
property of the Graphics so that drawing the original image into the new
one is rotated as you desire, and then just draw the original image
directly into the new one.

Pete
 
S

Steve K.

Peter Duniho said:
Ah. Well, not something I know about first-hand, but that sounds about
right. I'd guess the RotateFlip() method is just a simple helper that
basically creates a new internal image, copying the original into the new
one thereby replacing it.


Sounds like a reasonable workaround to me. I don't view the .NET
Framework as being a full-featured image editing framework. It has some
basic functionality, but it still leaves lots of things for you to manage
manually. Assuming .NET has a way for you to generate a multi-frame image
(haven't done that myself), that seems like a better way to go.

I agree, it can't do it all. It does somethings so well that I've come to
expect it to "do everything" which of course is unreasonable! ;0)
BTW, if performance is important, you may want to avoid using RotateFlip()
in this case, given that it does generate a brand new image without any
other frames. Using RotateFlip(), you'd have to copy your original Image
so that you don't muck it up with the call to RotateFlip(), and then copy
the rotated image into the new Image you're building.

Performance is not an issue, however this is a good point and something I
will keep in mind.

Instead, you should just use Graphics.FromImage() on the Image you're
building so that you can draw into its current frame, set the Transform
property of the Graphics so that drawing the original image into the new
one is rotated as you desire, and then just draw the original image
directly into the new one.

Yes, this is what I've started to do.

Thanks again for the great help Peter, I appreciate it.
-Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top