当前上下文 xamarin 中不存在 ImageHandlers 和 GetEncoder,怎么办?

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

我需要创建缩略图以节省应用程序的性能我有这段代码,它告诉我 GetEncoder 和 ImageHandlers 在当前上下文中不存在。你知道为什么它不起作用吗?您还知道如何更好地制作缩略图吗?

代码如下:

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);
    }

我用过 Skiasharp 并且有效:

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