我正在使用 android 的 Bitmapfun 应用程序来有效地加载位图。但有时在 BitmapFactory.decodeFileDescriptor() 会发生崩溃。日志cat和函数如下。crash发生在return语句中。请帮助我。在此先感谢。
public static Bitmap decodeSampledBitmapFromDescriptor(
FileDescriptor fileDescriptor, int reqWidth, int reqHeight, ImageCache cache) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
// If we're running on Honeycomb or newer, try to use inBitmap
if (Utils.hasHoneycomb()) {
addInBitmapOptions(options, cache);
}
return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
}
日志猫
06-25 14:20:56.055: E/AndroidRuntime(5978): FATAL EXCEPTION: AsyncTask #3
06-25 14:20:56.055: E/AndroidRuntime(5978): java.lang.RuntimeException: An error occured while executing doInBackground()
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.AsyncTask$3.done(AsyncTask.java:325)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.lang.Thread.run(Thread.java:856)
06-25 14:20:56.055: E/AndroidRuntime(5978): Caused by: java.lang.IllegalArgumentException: Problem decoding into existing bitmap
06-25 14:20:56.055: E/AndroidRuntime(5978): at android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:664)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.ImageResizer.decodeSampledBitmapFromDescriptor(ImageResizer.java:196)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.ImageFetcher.processBitmap(ImageFetcher.java:242)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.ImageFetcher.processBitmap(ImageFetcher.java:255)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.ImageWorker$BitmapWorkerTask.doInBackground(ImageWorker.java:326)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.ImageWorker$BitmapWorkerTask.doInBackground(ImageWorker.java:1)
06-25 14:20:56.055: E/AndroidRuntime(5978): at com.vbk.vobok.util.AsyncTask$2.call(AsyncTask.java:313)
06-25 14:20:56.055: E/AndroidRuntime(5978): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-25 14:20:56.055: E/AndroidRuntime(5978): ... 4 more