在 Assets Android 中获取尺寸图像
Get dimensions image in Assets Android
在资产 Android 中 image.png,如何获取尺寸?
我试过了,但是没用。
String image = "my_image.png"
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(context.getAssets() + "/" + image, options);
// BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/other_dir/" + image, options);
int width_t = options.outWidth;
int height_t = options.outHeight;
如果图像在 /other_dir/ 中,我可以获得尺寸,但不能在 Asset 中。
试试这个:
AssetManager asset = context.getAssets();
InputStream is;
try {
is = asset.open("my_image.png");
} catch (IOException e) {
return null;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
int width_t = options.outWidth;
int height_t = options.outHeight;
在资产 Android 中 image.png,如何获取尺寸?
我试过了,但是没用。
String image = "my_image.png"
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(context.getAssets() + "/" + image, options);
// BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/other_dir/" + image, options);
int width_t = options.outWidth;
int height_t = options.outHeight;
如果图像在 /other_dir/ 中,我可以获得尺寸,但不能在 Asset 中。
试试这个:
AssetManager asset = context.getAssets();
InputStream is;
try {
is = asset.open("my_image.png");
} catch (IOException e) {
return null;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
int width_t = options.outWidth;
int height_t = options.outHeight;