Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi how rotate tiff image?

i use this code! and rotate frams of the tiff Image. but when add this frame to new List dont work?


when use
encoder.Save(st)
rotate fram and save to file. but when add to allFrameno rotated!

C#
var allFrame=new List<BitmapFram>();

var encoder=new JpegBitmapEncoder{Rotation=rotation};
encoder.Frames.Add(frm);
using(Stream st=new FileStream(@"c:\\1.tiff",FileMode.Create))
{
encoder.Save(st);//rotate fram 

}

allFrame.AddRange(encoder.Frames);
Posted

Do the following:
  1. load the image as a bitmap System.Drawing.Bitmap, using one of the constructors of this class:
    https://msdn.microsoft.com/en-us/library/system.drawing.bitmap(v=vs.110).aspx[^].
  2. Create a target bitmap of the size expected after the rotation, using, say, this constructor: https://msdn.microsoft.com/en-us/library/3z132tat%28v=vs.110%29.aspx[^].
  3. Draw source bitmap in the target bitmap. For this purpose, first create an instance of System.Drawing.Graphics to be used to draw on a target bitmap, from its reference:
    https://msdn.microsoft.com/en-us/library/System.Drawing.Graphics%28v=VS.110%29.aspx[^],
    https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage(v=vs.110).aspx[^].

    Last link references the factory method you can use to obtain the Graphics instance.
  4. Before the call to the drawing method, make sure the drawing is done with rotation. For this purpose, perform coordinate transform. You can use this property: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.transform(v=vs.110).aspx[^].

    This is how can you obtain the transform matrix object representing required rotation:
    https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix(v=vs.110).aspx[^],
    https://msdn.microsoft.com/en-us/library/k7dwd0wc(v=vs.110).aspx[^].

    The above approach is the very general one, can be used to perform complex coordinate transform, combining several matrices my multiplying them, which represents the multiplication (read it "multiple application") of several transform operators. If you need just one rotation, the shortcut would be application of the transform immediately on your instance of Graphics using the method Graphics.RotateTransform:
    https://msdn.microsoft.com/en-us/library/a0z3f662%28v=vs.110%29.aspx[^].
  5. Perform drawing of the source bitmap on the target bitmap using one of the System.Drawing.Graphics.DrawImage methods: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[^].
  6. Save the target bitmap in required format: https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.save%28v=vs.110%29.aspx[^].
  7. PROFIT!


I gave you complete pseudo-code in the form of the sequential set of operations. This is all you need.

—SA
 
Share this answer
 
You can use the Image.RotateFlip[^] method.

MSDN has a pretty good example to get started with, but here is a very small code sample:
C#
// Load an image from disk
Image img = Image.FromFile(@"your file path");
// Rotates the image clockwise 90 degrees
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900