简体   繁体   中英

ImageHandlers and GetEncoder doesnt exists in current context xamarin, what to do?

I need to create thumbnails to save performance in app i have this code and it writes me GetEncoder and ImageHandlers doesnt exists in current context. Do you know why it isnt working? Also do you know better way how to do thumbnail?

here is code:

public static void CreatePreviewImage(string imageFullFilename, string previewFullFilename)
    {
        ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
        // Create an Encoder object based on the GUID  
        // for the Quality parameter category.  
        System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
        // Create an EncoderParameters object.  
        // An EncoderParameters object has an array of EncoderParameter  
        // objects. In this case, there is only one
        // EncoderParameter object in the array.  
        EncoderParameters myEncoderParameters = new EncoderParameters(1);
        EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 75L); //default
        myEncoderParameters.Param[0] = myEncoderParameter;

        Bitmap originalimage = (Bitmap)System.Drawing.Image.FromFile(imageFullFilename, true);
        originalimage.SetResolution(72, 72);

        int w = originalimage.Width;
        int h = originalimage.Height;
        int pw = 0;
        int ph = 0;

        h = originalimage.Height * w / originalimage.Width;

        if (w > h)
        {
            pw = 200;
            ph = h * pw / w;
        }
        else
        {
            ph = 200;
            pw = w * ph / h;
        }

        Bitmap previewImage = ImageHandlers.ResizeImage(originalimage, pw, ph);
        previewImage.Save(previewFullFilename, jpgEncoder, myEncoderParameters);
    }

I have used Skiasharp and it works:

var resizedImage = bitmap.Resize(new SKImageInfo(newWidth, newHeight), SKBitmapResizeMethod.Lanczos3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM