如何旋转tiff图像? [英] how rotate tiff image?

查看:528
本文介绍了如何旋转tiff图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
如何旋转tiff图像?



我使用此代码!并旋转tiff图像的帧。但是当这个框架添加到新的列表时不工作?





使用时

 encoder.Save(st)

旋转fram并保存到文件。但是当添加到allFrameno旋转时!



  var  allFrame =  new  List< BitmapFram>(); 

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

}

allFrame.AddRange(encoder.Frames);

解决方案

执行以下操作:

  1. 将图像作为位图加载 System.Drawing.Bitmap ,使用此类的一个构造函数:

    https://msdn.microsoft.com/en-us/library/system.drawing.bitmap(v=vs.110 ).aspx [ ^ ]。
  2. 使用,例如,使用此构造函数创建旋转后大小的目标位图 https://msdn.microsoft.com/en-us/library/3z132tat% 28v = vs.110%29.aspx [ ^ ]。
  3. 在目标位图中绘制源位图。为此,首先创建一个 System.Drawing.Graphics 的实例,用于在目标位图上绘制,参考位置为:

    < a href =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%28v=VS.110%29.aspx [ ^ ],

    https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage( v = vs.110).aspx [ ^ ]。



    最后一个链接引用工厂方法你可以用来获取 Graphics 实例。
  4. 在调用绘图方法之前,make确保绘图是通过旋转完成的。为此,执行坐标转换。您可以使用此属性: https:// msdn .microsoft.com / zh-cn / library / system.drawing.graphics.transform(v = vs.110).aspx [ ^ ]。



    这是如何获得代表所需轮换的变换矩阵对象

    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 [ ^ ]。

    Graphics.RotateTransform Graphics 实例上应用转换$ c>:

    https:// msdn.microsoft.com/en-us/library/a0z3f662%28v=vs.110%29.aspx [ ^ ]。
  5. 使用以下方法之一在目标位图上绘制源位图 System.Drawing.Graphics.DrawImage 方法: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx [ ^ ]。
  6. 将目标位图保存在r中所需格式: https://msdn.microsoft .com / zh-CN / library / system.drawing.bitmap.save%28v = vs.110%29.aspx [ ^ ]。
  7. 利润!





我以顺序操作集的形式为您提供了完整的伪代码。这就是你所需要的。



-SA


你可以使用 Image.RotateFlip [ ^ ]方法。



MSDN有一个很好的例子可以开始使用,但这里有一个非常小的代码示例:

  //  从磁盘加载图像 
Image img = Image.FromFile( @ 你的文件路径);
// 顺时针旋转图像90度
image.RotateFlip(RotateFlipType。 Rotate90FlipNone);


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!

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);

解决方案

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


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:

// Load an image from disk
Image img = Image.FromFile(@"your file path");
// Rotates the image clockwise 90 degrees
image.RotateFlip(RotateFlipType.Rotate90FlipNone);


这篇关于如何旋转tiff图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆