Android 要发送到handleSamplingAndRotationBitmap的正确URI是什么?

Android 要发送到handleSamplingAndRotationBitmap的正确URI是什么?,android,android-bitmap,bitmapfactory,Android,Android Bitmap,Bitmapfactory,我有一个常见的问题,就是以正确的旋转方式显示图片。我的图像存储在服务器上。我调用图像并将其显示在我的应用程序中。每个图像都是旋转的。因此,我发现了一个修正与handleSamplingAndRotationBitmap public static Bitmap handleSamplingAndRotationBitmap(Context context, Uri selectedImage) throws IOException { int MAX_HEIGHT = 1

我有一个常见的问题,就是以正确的旋转方式显示图片。我的图像存储在服务器上。我调用图像并将其显示在我的应用程序中。每个图像都是旋转的。因此,我发现了一个修正与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/etablisement/aboradage.jpg(否 此类文件或目录)

您知道如何发送正确的URI吗


谢谢

如果您有一个正确的url,您将发送正确的url。但是url是一个http url,不能由位图工厂等处理。先自己下载文件。@blackapps谢谢。。。我不明白你的答案。在尝试旋转之前,我使用了InputStream in=newurl(urldisplay).openStream();mIcon=BitmapFactory.decodeStream(in),因此url可以由位图工厂处理。在本例中,问题是将Uri中的urldisplay转换为输入HandleSamplingandRotationBitMap,而不必解释代码。这是完全错误的。由于在http url上使用文件输入流,因此出现“未找到文件”异常。谷歌如何下载文件。