image processing - Rotating JPEGs in .NET with minimal loss of quality -
I am trying to rotate JPEG images from ASP.NET MVC (in increments of 90 degree increments). I'm trying to use the System.Drawing
(GDI +), though I'm running into issues.
I tried to use that which is capable of rotating the image but causes the loss of quality. Even with the 100 encoder quality, there are still things that are visible on the rotated image which were not on the original image, nor when I used it to rotate it using other programs (gimp, etc.) I show.
Using (image image = image.framefile ("C: \\ source.jpg")) {ImageFormat sourceFormat = image.RawFormat; Image.RotateFlip (RotateFlipType.Rotate90FlipNone); Encoder parameter encoder = null; Try (if (sourceFormat == ImageFormat.Jpeg) {encoder perm = new encoder parameter (1); Ankoderprmkpam [0] = new Ankoderpramitr (encoder. Quality, 100 L);} Image.Save ( "C: \ \ target.jpg ", GetEncoder (Srotformet), Ankoderprms);} finally {if (encoder perm! = null) encoder Params. Dispojh ();}}
I found an article Looks for the encoder.configuration
from NOAT - although I can rotate it from any of my JPEG exams. Whether it is a value of dimension 16 or not.
using (image image = image.framefile ("C: \\ source.jpg")) { ImageFormat sourceFormat = image.RawFormat; encoder parameters Ankoderprm = null; try (if (sourceFormat == ImageFormat.Jpeg) {encoder perm = new encoder parameter (1); encoder Paramskpam [0] = new Ankoderpramitr (encoder Ksnrcna , (Long) encoder value. Transformatate 90);} Image.Save ("C: \\ target.jpg", GetEncoder (source format), encoderprom);} end In {if (encoder perm! = Null) Encoder Params Dispos (); Does anyone know that in a way that jpeg successfully rotates in .net at 90 degree intervals, at least or without any loss, methods or any other method. Should use? Thank you. Also, here is my GetEncoder
:
Private Image Kodekinfo GetEncoder (ImageFormat format) {foreach (varC ()) if (info. FormatID == format.Guid) Return information; Return tap; }
Edit:
I updated the above code to better match my actual code. The bug was in the following line:
if (sourceFormat == ImageFormat.Jpeg) {
it should have been:
< Code> if (sourceFormat.Guid == ImageFormat.Jpeg.Guid) {
any With the disintegration of the image by the method, it rotates and compresses it, you have a loss of quality.
JPEG format all the four compressed color information of the sections of 2x2 pixels obtained by color to represent pixels, so if your image width and height are divisible by two, so you less The quality will be lost because most of the information collected in the compression is the information that was launched in the decompression.
Similarly the brightness information is compressed to a square of 8x8 pixels, so if your width and height is divisible by eight, then the grid will align the image after rotating and you will lose less actual information .
The study, you must use fully diff first method, JPEG files to lossless rotation and change again each class of information and rotating to so that pressure without the rotated image and reprocess Makes it without
Comments
Post a Comment