android - 发送到 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 吗?
谢谢
解决方案
推荐阅读
- bash - echo 覆盖 bash 脚本中的行首
- phalcon - 在 RHEL 7 上安装 Phalcon
- javascript - 重新排序 JavaScript 编号列表
- sql-server - 确定proc B的调用者是否是proc A
- flutter - 如何在颤振插件中使用 z3
- c# - LINQ 从列表中选择项目并从原始列表中保存它们的索引
- python - 向分区数据集添加新值 Pyarrow
- microsoft-graph-api - 对 OnPremise Exchange 的 Graph API 调用仅适用于 Playground
- r - R coxph 为时变协变量返回 NA
- php - 没有中间件的 Laravel 8 API 测试