可能有两个可能的原因,第一个是在创建位图时,第二个是将位图转换为BitmapDrawable时。正如我可以从您的评论(new BitmapDrawable(currentFrameBitmap)
现在看到此方法折旧更好使用BitmapDrawable(getResources(),currentFrameBitmap)
没有资源引用,位图可能无法正确呈现,即使正确缩放。为了有效地加载位图,您可以正确调整它。
public class BitmapDecoderHelper {
private Context context;
public BitmapDecoderHelper(Context context){
this.context = context;
}
public int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
Log.d("height reqheight width reqwidth", height+"//"+reqHeight+"//"+width+"///"+reqWidth);
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 Bitmap decodeSampledBitmapFromResource(String filePath,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
Log.d("options sample size", options.inSampleSize+"///");
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
// out of memory occured easily need to catch and test the things.
return BitmapFactory.decodeFile(filePath, options);
}
public int getPixels(int dimensions){
Resources r = context.getResources();
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dimensions, r.getDisplayMetrics());
return px;
}
public String getFilePath(Uri selectedImage){
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
return filePath;
}
}
你能发布每个设备的总RAM吗?另外,你在谈论什么样的动画?你可以发布一个初始化代码的例子吗? –
XOOM有1GB Ram,我使用清单中的“大堆”标志,Galaxy S有512MB – Gu1234
这个'myAnimation.addFrame'让我怀疑你可能没有按照它的意图使用它。请发布一小段代码。 –