views:

382

answers:

0

hello, am am trying to crop an image that is a jpeg image on the hard disk(imgOld) and save it at the same quality as the image it was cropped from

Image imgCropped = cropImage(imgOld, new Rectangle(iDiskCropX, iDiskCropY, iDiskCropWidth, iDiskCropHeight));

        ImageCodecInfo codecJpeg = this.getEncoderInfo("image/jpeg");

        EncoderParameters encparams = imgOld.GetEncoderParameterList(codecJpeg.Clsid);


        try
        {
            imgCropped.Save("C:\\a.jpg",codecJpeg, encparams);
        }
        catch (Exception ex)
        {
            DisplayError(ex.Message);
        }

private static Image cropImage(Image img, Rectangle cropArea)
    {
        Bitmap bmpImage = new Bitmap(img);
        Bitmap bmpCrop = bmpImage.Clone(cropArea,
        bmpImage.PixelFormat);
        return (Image)(bmpCrop);
    }

I get the exception {"Parameter is not valid."} when saving If I save imgCropped.Save("C:\a.jpg") I get no error but I don't know now if the cropped jpg has the same quality as the original? does it? can I do anything to solve this exception? can I get the quality any other way?

thank you in advance