首页 > 解决方案 > 发送到 handleSamplingAndRotationBitmap 的正确 URI 是什么?

问题描述

我有一个以正确旋转显示图片的常见问题。我的图像存储在服务器上。我调用图像并将其显示在我的应用程序中。每个图像都被旋转。所以我用handleSamplingAndRotationBitmap 找到了一个修正。

public static Bitmap handleSamplingAndRotationBitmap(Context context, Uri selectedImage)
        throws IOException {
    int MAX_HEIGHT = 1024;
    int MAX_WIDTH = 1024;

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    InputStream imageStream = context.getContentResolver().openInputStream(selectedImage);
    BitmapFactory.decodeStream(imageStream, null, options);
    imageStream.close();

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, MAX_WIDTH, MAX_HEIGHT);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    imageStream = context.getContentResolver().openInputStream(selectedImage);
    Bitmap img = BitmapFactory.decodeStream(imageStream, null, options);

    img = rotateImageIfRequired(img, selectedImage);
    return img;
}

但是我不可能发送正确的 Uri selectedImage。

protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon = null;
            final String myUrlStr = urldisplay;
            URL url;


            try {
                url = new URL(myUrlStr);
                uri = Uri.fromFile(new File(urldisplay));
                uri2 = Uri.parse((urldisplay).toString());

                mIcon = handleSamplingAndRotationBitmap(getContext(),uri2);
               } catch (MalformedURLException e1) {
                e1.printStackTrace();
            }

我有错误

} catch (FileNotFoundException e) {
            InputStream in = null;
            try {
                in = new URL(DataConstantes.lien_URLEtb + "Aucune_photo_etablissement.png").openStream();
            } catch (IOException e1) {
                flagError = true;
            }
            mIcon = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            flagError=true;
        }

java.io.FileNotFoundException: /http:/$$$$$$$$$$/appli/android_connect/Etablissement/abordage.jpg (没有这样的文件或目录)

你知道我如何发送正确的 URI 吗?

谢谢

标签: androidandroid-bitmapbitmapfactory

解决方案


推荐阅读