Le redimensionnement d'une image JPEG en C# réduit sa résolution

Ce que j'ai:

   A JPEG image with 96dpi, size: 540 X 700

Ce que je Veux:
Image JPEG avec 300dpi, taille: 771 X 1000

Problème:
Quand j'ai redimensionner l'image d'abord, puis essayez de changer la résolution, à travers le code suivant il ne marche pas

       ///<summary>
    ///Changes the resolution of the image
    ///</summary>
    ///<param name="imgPath">Image Path</param>
    ///<param name="xResolution">x Resolution</param>
    ///<param name="yResolution">y Resolution</param>
    ///<returns>Modified Image Path</returns>
    private string ChangeResolution(string imgPath, int xResolution, int yResolution)
    {
        string fullFileName = Path.GetFileNameWithoutExtension(imgPath);
        string extension = Path.GetExtension(imgPath);
        string tmpFileSavedPath = outputDir + "\\" + fullFileName + "_." + extension + "_tmp";

        Image original = Bitmap.FromFile(imgPath);
        original.Save(tmpFileSavedPath);

        Bitmap bmSmall = new Bitmap(tmpFileSavedPath);
        bmSmall.SetResolution(xResolution, yResolution);
        string modifiedOverLayImagePath = tmpFileSavedPath.TrimEnd("_tmp".ToCharArray());
        bmSmall.Save(modifiedOverLayImagePath);
        bmSmall.Dispose();

        //Deleting temp file
        System.IO.File.Delete(tmpFileSavedPath);
        return modifiedOverLayImagePath;
    }

signifie qu'il ne fait rien à l'image, la résolution reste la même, si je vais de l'autre sens, c'est à dire changer la résolution en premier et ensuite modifier la taille, de façon surprenante, la taille est changé, mais la résolution est réduit à 96 ppp.

Ici est le redimensionnement de code:

public static System.Drawing.Bitmap ResizeImage(System.Drawing.Image image, int width, int height)
    {
        //a holder for the result
        Bitmap result = new Bitmap(width, height);

        //use a graphics object to draw the resized image into the bitmap
        using (Graphics graphics = Graphics.FromImage(result))
        {
            //set the resize quality modes to high quality
            graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //draw the image into the target bitmap
            graphics.DrawImage(image, 0, 0, result.Width, result.Height);
        }

        //return the resulting bitmap
        return result;
    }

Quelqu'un peut-il m'aider, je me demandais si 771 X 1000 prend en charge une résolution de 300 ppp, mais quand je fais cela dans photoshop, il fonctionne parfaitement, merci

Qui suit est ma fonction principale dans laquelle je suis l'évolution de la résolution de la première et de redimensionnement par la suite:

string imgPath = @"D:\abc\background.jpg";

        string newResPath = ChangeResolution(imgPath, 300, 300);

        Image oldImage = Bitmap.FromFile(newResPath);
        //Image newImage = ImageResize.ConstrainProportions(oldImage, 771, ImageResize.Dimensions.Width);
        Image newImage = ImageUtilities.ResizeImage(oldImage, 771, 1000);
        string savedPath = "D:\\abc\\saved.jpg";

        try
        {
            newImage.Save(savedPath, ImageFormat.Jpeg);
        }
        catch
        {
            MessageBox.Show("error");
        }
        newImage.Dispose();
InformationsquelleAutor shabby | 2012-01-18