[英]Android ffmpeg : Use image for Watermark from drawable or assets folder
[英]Properly loading large image from drawable/assets folder in Android
我從assets / drawable-nopdpi文件夾中獲得了一個相當大的圖像。 圖片大小為1173x1285,497KB。 它沒有加載..
onCreate
AssetManager assetManager = this.getAssets();
Bitmap bitmap = null;
InputStream is = null;
try {
is = assetManager.open("indoormapimg.png");
bitmap = decodeSampledBitmapFromResource(is, 100, 100); //trying 100x100
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("tag", String.valueOf("Bitmap: " + bitmap));
方法
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth)
if (width > height)
inSampleSize = Math.round((float)height / (float)reqHeight);
else
inSampleSize = Math.round((float)width / (float)reqWidth);
return inSampleSize;
}
和
public static Bitmap decodeSampledBitmapFromResource(InputStream is, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(is, null, options);
}
我也嘗試過參考資料。 無濟於事。我也嘗試了inJustBounds
true和false的BitmapFactory。 也可以使用inScaled
我似乎無法加載任何圖像,我的日志始終返回null。
編輯:
我也在努力
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), ResID);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
opts.inScaled = false;
Bitmap bitmapImage = BitmapFactory.decodeResource(this.getResources(), ResID, opts);
Log.d("tag", String.valueOf("Bitmap: " + bitmap + " BitmapImage: " + bitmapImage));
返回Bitmap: null BitmapImage: null
另外,LogCat顯示--- decoder->decode returned false
原來,我正在解碼的文件已損壞。 我不得不更改原始文件。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.