如何旋转jpg而不丢失格式? [英] How to rotate a jpg without losing format?

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

问题描述

我想在VB中制作一个程序,该程序可以将图像旋转90度,然后将其保存为旋转状态(在查看图像时,例如Windows Picture Viewer).

如果我尝试制作一个Image对象,然后旋转它,然后保存它,那么它的大小会有所不同(例如,我有1.21 MB的文件,旋转后我得到的图像旋转为3.20 MB).

如何直接在jpg上工作?
还是有其他方法可以旋转图像并保持相同的分辨率(因为Horizo​​ntalResolution和VerticalResolution是ReadOnly属性)

I want make a program in VB which can rotate images with 90 degrees and then saves them as rotated (while viewing them, like the windows Picture Viewer).

If I try to make an Image object, then rotate it and then save it then its size will differ (e.g. I had a file of 1.21 MB and after I rotated it I got the same image rotated with 3.20 MB).

How can I work directly on jpg?
Or is there any other method of rotating an image and keeping the resolution the same (because HorizontalResolution and VerticalResolution are ReadOnly properties)

推荐答案

如果旋转图像,则可以这可能会影响图像尺寸的三个问题.
1)如果未将其旋转到与原始宽度和高度相同的宽度和高度.例如,如果将方形图像旋转45度,则生成的图像需要一个更大的正方形才能放置-所有图像均基于矩形框.
2)Jpeg文件使用有损压缩-当您旋转图像任何数量时,您最终可能会得到不压缩的图像.这可以使文件大得多.
3)编写jpeg文件时,可以调节压缩量.如果用于保存图像的例程与保存原始图像的例程不同,或者如果压缩参数有任何不同,则结果文件的大小将不相同.

一般来说,对jpeg文件进行任何图像处理(包括旋转)都是一个坏主意. Jpeg是一种有损压缩算法,因此任何后续处理都已在降级图像上进行.如果可以的话,可以直接从原始位图或其他非损耗压缩格式工作,然后将jpeg保存为单独的文件.
If you rotate an image, then there are three problems which may affect the image size.
1) If you do not rotate it to a width and height which are the same as the original. For example, if you rotate a square image by 45 degrees, the resulting image needs a bigger square in which to sit - and all images are based on a rectangular box.
2) Jpeg files use a lossy compression - when you rotate an image by any amount, you may well end up with an image which does not compress as well. This can make the file significantly bigger.
3) When you write a jpeg file, the compression amount can be adjusted. If the routine used to save the image is not the same as the original image was saved with, or if the compression parameters are different in any way, teh resulting file will not be the same size.

Generally speaking it is a bad idea to do any image processing on a jpeg file (including rotating it). Jpeg is a lossy compression algorithm, so any sbsequent processing is already working on a degraded image. Work directly from an original bitmap or other non-lossy compressed format) if you can, and save jpegs from that as separate files.



浏览此链接-
C#Image/PictureBox旋转 [ .NET中的图像旋转 [
Hi,
Go through this link-
C# Image/PictureBox Rotations[^]
Image Rotation in .NET[^]


请尝试以下操作(在解决方案2中看到您的评论:

1)如果您在.NET中",则只能使用图像"或位图"(在GDI或GDI +中).
2)保存图像时,可以使用".jpg"或".jpeg".但是,所有图像处理都在.NET环境(GDI或GDI +)中使用图像"和位图"进行.

3)将图像加载为位图.
4)获取原始图片的版本和荷尔分辨率并将其保存在某些变量(xDpi,yDpi)中.
5)旋转完成后,再次设置分辨率(xDpi,yDpi).

注意:
但是,旋转90度,我认为可以使用Bitmap或Image对象的RotateFlip属性完成操作,并且不会改变分辨率:

image.RotateFlip(RotateFlipType.Rotate90FlipNone);
Please try the following (after seeing your comment in solution 2):

1) If "you are inside .NET" you can only work with "Image" or "Bitmap" (in GDI or GDI+).
2) You can use ".jpg" or ".jpeg" when you are saving images. However, all image processings happen with "Image" and "Bitmap" in the .NET environment (GDI or GDI+).

3) Load the image as a Bitmap.
4) Get original image''s Ver. and Hor. resolutions and hold them in some variables (xDpi, yDpi).
5) After rotate is completed, set the resolution again (xDpi, yDpi).

NOTICE:
But, rotating 90 degrees, I think can be completed with RotateFlip property of the Bitmap or Image object and it won''t change the resolution:

image.RotateFlip(RotateFlipType.Rotate90FlipNone);


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

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