/** * Get a bitmap from the image path * * @param imagePath * @param sampleSize * @return bitmap or null if read fails */ public static Bitmap getBitmap(final String imagePath, int sampleSize) { final Options options = new Options(); options.inDither = false; options.inSampleSize = sampleSize; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); return BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) { try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } } }
/** * Get size of image * * @param imagePath * @return size */ public static Point getSize(final String imagePath) { final Options options = new Options(); options.inJustDecodeBounds = true; RandomAccessFile file = null; try { file = new RandomAccessFile(imagePath, "r"); BitmapFactory.decodeFileDescriptor(file.getFD(), null, options); return new Point(options.outWidth, options.outHeight); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); return null; } finally { if (file != null) { try { file.close(); } catch (IOException e) { Log.d(TAG, e.getMessage(), e); } } } }
BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache); int nextWidth = sBitmapOptionsCache.outWidth >> 1; Bitmap b = BitmapFactory.decodeFileDescriptor( fd.getFileDescriptor(), null, sBitmapOptionsCache);
BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache); int nextWidth = sBitmapOptionsCache.outWidth >> 1; Bitmap b = BitmapFactory.decodeFileDescriptor( fd.getFileDescriptor(), null, sBitmapOptionsCache);
result = BitmapFactory.decodeFileDescriptor(fd, null, options);
BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); if (options.outWidth == -1 || options.outHeight == -1) { return new BitmapWorkerResult(new IllegalArgumentException("Bounds for bitmap could not be retrieved from the Uri: [" + mInputUri + "]")); while (!decodeAttemptSuccess) { try { decodeSampledBitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); decodeAttemptSuccess = true; } catch (OutOfMemoryError error) {
@SuppressWarnings("ObjectToString") @Test public void decodeFileDescriptor_shouldGetWidthAndHeightFromHints() throws Exception { File tmpFile = File.createTempFile("BitmapFactoryTest", null); try { tmpFile.deleteOnExit(); try (FileInputStream is = new FileInputStream(tmpFile)) { FileDescriptor fd = is.getFD(); ShadowBitmapFactory.provideWidthAndHeightHints(fd, 123, 456); Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd); assertEquals("Bitmap for fd:" + fd, shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); } } finally { tmpFile.delete(); } }
bitmap = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, mNewOpts); } else { bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder_disk_210, mNewOpts);
/** * The real place to delegate bitmap decoding to BitmapFactory. */ public Bitmap decodeFileDescriptor(FileDescriptor fd, BitmapFactory.Options options) { if (options.mCancel) { return null; } Thread thread = Thread.currentThread(); if (!canThreadDecoding(thread)) { // Log.d(TAG, "Thread " + thread + " is not allowed to decode."); return null; } setDecodingOptions(thread, options); Bitmap b = BitmapFactory.decodeFileDescriptor(fd, null, options); removeDecodingOptions(thread); return b; } }
/** * The real place to delegate bitmap decoding to BitmapFactory. */ public Bitmap decodeFileDescriptor(FileDescriptor fd, BitmapFactory.Options options) { if (options.mCancel) { return null; } Thread thread = Thread.currentThread(); if (!canThreadDecoding(thread)) { // Log.d(TAG, "Thread " + thread + " is not allowed to decode."); return null; } setDecodingOptions(thread, options); Bitmap b = BitmapFactory.decodeFileDescriptor(fd, null, options); removeDecodingOptions(thread); return b; } }
private static Bitmap getMiniThumbFromFile(Cursor c, Uri baseUri, ContentResolver cr, BitmapFactory.Options options) { Bitmap bitmap = null; Uri thumbUri = null; try { long thumbId = c.getLong(0); thumbUri = ContentUris.withAppendedId(baseUri, thumbId); ParcelFileDescriptor pfdInput = cr.openFileDescriptor(thumbUri, "r"); bitmap = BitmapFactory.decodeFileDescriptor(pfdInput.getFileDescriptor(), null, options); pfdInput.close(); } catch (FileNotFoundException ex) { Log.e("getMiniThumbFromFile", ex); } catch (IOException ex) { Log.e("getMiniThumbFromFile", ex); } catch (OutOfMemoryError ex) { Log.e("getMiniThumbFromFile", ex); } return bitmap; }
/** * 获取bitmap * * @param fd 文件描述 * @return bitmap */ public static Bitmap getBitmap(FileDescriptor fd) { if (fd == null) return null; return BitmapFactory.decodeFileDescriptor(fd); }
/** * 获取bitmap * * @param fd 文件描述 * @return bitmap */ public static Bitmap getBitmap(FileDescriptor fd) { if (fd == null) return null; return BitmapFactory.decodeFileDescriptor(fd); }
/** * 获取bitmap * * @param fd 文件描述 * @return bitmap */ public static Bitmap getBitmap(FileDescriptor fd) { if (fd == null) return null; return BitmapFactory.decodeFileDescriptor(fd); }
/** * 压缩加载图片 从文件<br> */ public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor descriptor, int reqWidth, int reqHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFileDescriptor(descriptor, null, options); int inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; return BitmapFactory.decodeFileDescriptor(descriptor, null, options); }
private Bitmap decodeFileDescriptor() { if (!isFileDescriptor) return BitmapFactory.decodeFileDescriptor(getFD(), null, opts); else return BitmapFactory.decodeFile(filePath, opts); }
private Bitmap decodeFileDescriptorNoOpts() { if (!isFileDescriptor) return BitmapFactory.decodeFileDescriptor(getFD()); else return BitmapFactory.decodeFile(filePath); }
@Override public Bitmap decodeBitmapWithOptions(BitmapFactory.Options options) { try { return BitmapFactory.decodeFileDescriptor(fileInputStream.getFD(), null, options); } catch (IOException e) { e.printStackTrace(); } return null; } };
public static Bitmap requestDecode(JobContext jc, FileDescriptor fileDescriptor, Rect paddings, Options options) { if (options == null) options = new Options(); jc.setCancelListener(new DecodeCanceller(options)); return ensureGLCompatibleBitmap(BitmapFactory.decodeFileDescriptor (fileDescriptor, paddings, options)); }
public static Bitmap requestDecode(JobContext jc, FileDescriptor fd, Options options) { if (options == null) options = new Options(); jc.setCancelListener(new DecodeCanceller(options)); return ensureGLCompatibleBitmap( BitmapFactory.decodeFileDescriptor(fd, null, options)); }