BitmapFactory.java revision 3e8105e212e65005c0ef0ecc345b47eb0bf129bd
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19import android.content.res.AssetManager; 20import android.content.res.Resources; 21import android.os.Trace; 22import android.util.DisplayMetrics; 23import android.util.Log; 24import android.util.TypedValue; 25 26import java.io.FileDescriptor; 27import java.io.FileInputStream; 28import java.io.IOException; 29import java.io.InputStream; 30 31/** 32 * Creates Bitmap objects from various sources, including files, streams, 33 * and byte-arrays. 34 */ 35public class BitmapFactory { 36 private static final int DECODE_BUFFER_SIZE = 16 * 1024; 37 38 public static class Options { 39 /** 40 * Create a default Options object, which if left unchanged will give 41 * the same result from the decoder as if null were passed. 42 */ 43 public Options() { 44 inDither = false; 45 inScaled = true; 46 inPremultiplied = true; 47 } 48 49 /** 50 * If set, decode methods that take the Options object will attempt to 51 * reuse this bitmap when loading content. If the decode operation 52 * cannot use this bitmap, the decode method will return 53 * <code>null</code> and will throw an IllegalArgumentException. The 54 * current implementation necessitates that the reused bitmap be 55 * mutable, and the resulting reused bitmap will continue to remain 56 * mutable even when decoding a resource which would normally result in 57 * an immutable bitmap.</p> 58 * 59 * <p>As of {@link android.os.Build.VERSION_CODES#KEY_LIME_PIE}, any 60 * mutable bitmap can be reused to decode any other bitmaps as long as 61 * the resulting {@link Bitmap#getByteCount() byte count} of the decoded 62 * bitmap is less than or equal to the {@link 63 * Bitmap#getAllocationByteCount() allocated byte count} of the reused 64 * bitmap. This can be because the intrinsic size is smaller, or its 65 * size post scaling (for density / sample size) is smaller.</p> 66 * 67 * <p>Prior to {@link android.os.Build.VERSION_CODES#KEY_LIME_PIE} 68 * additional constraints apply: The image being decoded (whether as a 69 * resource or as a stream) must be in jpeg or png format. Only equal 70 * sized bitmaps are supported, with {@link #inSampleSize} set to 1. 71 * Additionally, the {@link android.graphics.Bitmap.Config 72 * configuration} of the reused bitmap will override the setting of 73 * {@link #inPreferredConfig}, if set.</p> 74 * 75 * <p>You should still always use the returned Bitmap of the decode 76 * method and not assume that reusing the bitmap worked, due to the 77 * constraints outlined above and failure situations that can occur. 78 * Checking whether the return value matches the value of the inBitmap 79 * set in the Options structure will indicate if the bitmap was reused, 80 * but in all cases you should use the Bitmap returned by the decoding 81 * function to ensure that you are using the bitmap that was used as the 82 * decode destination.</p> 83 * 84 * @see Bitmap#reconfigure(int,int, android.graphics.Bitmap.Config) 85 */ 86 public Bitmap inBitmap; 87 88 /** 89 * If set, decode methods will always return a mutable Bitmap instead of 90 * an immutable one. This can be used for instance to programmatically apply 91 * effects to a Bitmap loaded through BitmapFactory. 92 */ 93 @SuppressWarnings({"UnusedDeclaration"}) // used in native code 94 public boolean inMutable; 95 96 /** 97 * If set to true, the decoder will return null (no bitmap), but 98 * the out... fields will still be set, allowing the caller to query 99 * the bitmap without having to allocate the memory for its pixels. 100 */ 101 public boolean inJustDecodeBounds; 102 103 /** 104 * If set to a value > 1, requests the decoder to subsample the original 105 * image, returning a smaller image to save memory. The sample size is 106 * the number of pixels in either dimension that correspond to a single 107 * pixel in the decoded bitmap. For example, inSampleSize == 4 returns 108 * an image that is 1/4 the width/height of the original, and 1/16 the 109 * number of pixels. Any value <= 1 is treated the same as 1. Note: the 110 * decoder uses a final value based on powers of 2, any other value will 111 * be rounded down to the nearest power of 2. 112 */ 113 public int inSampleSize; 114 115 /** 116 * If this is non-null, the decoder will try to decode into this 117 * internal configuration. If it is null, or the request cannot be met, 118 * the decoder will try to pick the best matching config based on the 119 * system's screen depth, and characteristics of the original image such 120 * as if it has per-pixel alpha (requiring a config that also does). 121 * 122 * Image are loaded with the {@link Bitmap.Config#ARGB_8888} config by 123 * default. 124 */ 125 public Bitmap.Config inPreferredConfig = Bitmap.Config.ARGB_8888; 126 127 /** 128 * If true (which is the default), the resulting bitmap will have its 129 * color channels pre-multipled by the alpha channel. 130 * 131 * <p>This should NOT be set to false for images to be directly drawn by 132 * the view system or through a {@link Canvas}. The view system and 133 * {@link Canvas} assume all drawn images are pre-multiplied to simplify 134 * draw-time blending, and will throw a RuntimeException when 135 * un-premultiplied are drawn.</p> 136 * 137 * <p>This is likely only useful if you want to manipulate raw encoded 138 * image data, e.g. with RenderScript or custom OpenGL.</p> 139 * 140 * <p>This does not affect bitmaps without an alpha channel.</p> 141 * 142 * @see Bitmap#hasAlpha() 143 * @see Bitmap#isPremultiplied() 144 */ 145 public boolean inPremultiplied; 146 147 /** 148 * If dither is true, the decoder will attempt to dither the decoded 149 * image. 150 */ 151 public boolean inDither; 152 153 /** 154 * The pixel density to use for the bitmap. This will always result 155 * in the returned bitmap having a density set for it (see 156 * {@link Bitmap#setDensity(int) Bitmap.setDensity(int)}). In addition, 157 * if {@link #inScaled} is set (which it is by default} and this 158 * density does not match {@link #inTargetDensity}, then the bitmap 159 * will be scaled to the target density before being returned. 160 * 161 * <p>If this is 0, 162 * {@link BitmapFactory#decodeResource(Resources, int)}, 163 * {@link BitmapFactory#decodeResource(Resources, int, android.graphics.BitmapFactory.Options)}, 164 * and {@link BitmapFactory#decodeResourceStream} 165 * will fill in the density associated with the resource. The other 166 * functions will leave it as-is and no density will be applied. 167 * 168 * @see #inTargetDensity 169 * @see #inScreenDensity 170 * @see #inScaled 171 * @see Bitmap#setDensity(int) 172 * @see android.util.DisplayMetrics#densityDpi 173 */ 174 public int inDensity; 175 176 /** 177 * The pixel density of the destination this bitmap will be drawn to. 178 * This is used in conjunction with {@link #inDensity} and 179 * {@link #inScaled} to determine if and how to scale the bitmap before 180 * returning it. 181 * 182 * <p>If this is 0, 183 * {@link BitmapFactory#decodeResource(Resources, int)}, 184 * {@link BitmapFactory#decodeResource(Resources, int, android.graphics.BitmapFactory.Options)}, 185 * and {@link BitmapFactory#decodeResourceStream} 186 * will fill in the density associated the Resources object's 187 * DisplayMetrics. The other 188 * functions will leave it as-is and no scaling for density will be 189 * performed. 190 * 191 * @see #inDensity 192 * @see #inScreenDensity 193 * @see #inScaled 194 * @see android.util.DisplayMetrics#densityDpi 195 */ 196 public int inTargetDensity; 197 198 /** 199 * The pixel density of the actual screen that is being used. This is 200 * purely for applications running in density compatibility code, where 201 * {@link #inTargetDensity} is actually the density the application 202 * sees rather than the real screen density. 203 * 204 * <p>By setting this, you 205 * allow the loading code to avoid scaling a bitmap that is currently 206 * in the screen density up/down to the compatibility density. Instead, 207 * if {@link #inDensity} is the same as {@link #inScreenDensity}, the 208 * bitmap will be left as-is. Anything using the resulting bitmap 209 * must also used {@link Bitmap#getScaledWidth(int) 210 * Bitmap.getScaledWidth} and {@link Bitmap#getScaledHeight 211 * Bitmap.getScaledHeight} to account for any different between the 212 * bitmap's density and the target's density. 213 * 214 * <p>This is never set automatically for the caller by 215 * {@link BitmapFactory} itself. It must be explicitly set, since the 216 * caller must deal with the resulting bitmap in a density-aware way. 217 * 218 * @see #inDensity 219 * @see #inTargetDensity 220 * @see #inScaled 221 * @see android.util.DisplayMetrics#densityDpi 222 */ 223 public int inScreenDensity; 224 225 /** 226 * When this flag is set, if {@link #inDensity} and 227 * {@link #inTargetDensity} are not 0, the 228 * bitmap will be scaled to match {@link #inTargetDensity} when loaded, 229 * rather than relying on the graphics system scaling it each time it 230 * is drawn to a Canvas. 231 * 232 * <p>This flag is turned on by default and should be turned off if you need 233 * a non-scaled version of the bitmap. Nine-patch bitmaps ignore this 234 * flag and are always scaled. 235 */ 236 public boolean inScaled; 237 238 /** 239 * If this is set to true, then the resulting bitmap will allocate its 240 * pixels such that they can be purged if the system needs to reclaim 241 * memory. In that instance, when the pixels need to be accessed again 242 * (e.g. the bitmap is drawn, getPixels() is called), they will be 243 * automatically re-decoded. 244 * 245 * For the re-decode to happen, the bitmap must have access to the 246 * encoded data, either by sharing a reference to the input 247 * or by making a copy of it. This distinction is controlled by 248 * inInputShareable. If this is true, then the bitmap may keep a shallow 249 * reference to the input. If this is false, then the bitmap will 250 * explicitly make a copy of the input data, and keep that. Even if 251 * sharing is allowed, the implementation may still decide to make a 252 * deep copy of the input data. 253 */ 254 public boolean inPurgeable; 255 256 /** 257 * This field works in conjuction with inPurgeable. If inPurgeable is 258 * false, then this field is ignored. If inPurgeable is true, then this 259 * field determines whether the bitmap can share a reference to the 260 * input data (inputstream, array, etc.) or if it must make a deep copy. 261 */ 262 public boolean inInputShareable; 263 264 /** 265 * If inPreferQualityOverSpeed is set to true, the decoder will try to 266 * decode the reconstructed image to a higher quality even at the 267 * expense of the decoding speed. Currently the field only affects JPEG 268 * decode, in the case of which a more accurate, but slightly slower, 269 * IDCT method will be used instead. 270 */ 271 public boolean inPreferQualityOverSpeed; 272 273 /** 274 * The resulting width of the bitmap, set independent of the state of 275 * inJustDecodeBounds. However, if there is an error trying to decode, 276 * outWidth will be set to -1. 277 */ 278 279 public int outWidth; 280 281 /** 282 * The resulting height of the bitmap, set independent of the state of 283 * inJustDecodeBounds. However, if there is an error trying to decode, 284 * outHeight will be set to -1. 285 */ 286 public int outHeight; 287 288 /** 289 * If known, this string is set to the mimetype of the decoded image. 290 * If not know, or there is an error, it is set to null. 291 */ 292 public String outMimeType; 293 294 /** 295 * Temp storage to use for decoding. Suggest 16K or so. 296 */ 297 public byte[] inTempStorage; 298 299 private native void requestCancel(); 300 301 /** 302 * Flag to indicate that cancel has been called on this object. This 303 * is useful if there's an intermediary that wants to first decode the 304 * bounds and then decode the image. In that case the intermediary 305 * can check, inbetween the bounds decode and the image decode, to see 306 * if the operation is canceled. 307 */ 308 public boolean mCancel; 309 310 /** 311 * This can be called from another thread while this options object is 312 * inside a decode... call. Calling this will notify the decoder that 313 * it should cancel its operation. This is not guaranteed to cancel 314 * the decode, but if it does, the decoder... operation will return 315 * null, or if inJustDecodeBounds is true, will set outWidth/outHeight 316 * to -1 317 */ 318 public void requestCancelDecode() { 319 mCancel = true; 320 requestCancel(); 321 } 322 } 323 324 /** 325 * Decode a file path into a bitmap. If the specified file name is null, 326 * or cannot be decoded into a bitmap, the function returns null. 327 * 328 * @param pathName complete path name for the file to be decoded. 329 * @param opts null-ok; Options that control downsampling and whether the 330 * image should be completely decoded, or just is size returned. 331 * @return The decoded bitmap, or null if the image data could not be 332 * decoded, or, if opts is non-null, if opts requested only the 333 * size be returned (in opts.outWidth and opts.outHeight) 334 */ 335 public static Bitmap decodeFile(String pathName, Options opts) { 336 Bitmap bm = null; 337 InputStream stream = null; 338 try { 339 stream = new FileInputStream(pathName); 340 bm = decodeStream(stream, null, opts); 341 } catch (Exception e) { 342 /* do nothing. 343 If the exception happened on open, bm will be null. 344 */ 345 Log.e("BitmapFactory", "Unable to decode stream: " + e); 346 } finally { 347 if (stream != null) { 348 try { 349 stream.close(); 350 } catch (IOException e) { 351 // do nothing here 352 } 353 } 354 } 355 return bm; 356 } 357 358 /** 359 * Decode a file path into a bitmap. If the specified file name is null, 360 * or cannot be decoded into a bitmap, the function returns null. 361 * 362 * @param pathName complete path name for the file to be decoded. 363 * @return the resulting decoded bitmap, or null if it could not be decoded. 364 */ 365 public static Bitmap decodeFile(String pathName) { 366 return decodeFile(pathName, null); 367 } 368 369 /** 370 * Decode a new Bitmap from an InputStream. This InputStream was obtained from 371 * resources, which we pass to be able to scale the bitmap accordingly. 372 */ 373 public static Bitmap decodeResourceStream(Resources res, TypedValue value, 374 InputStream is, Rect pad, Options opts) { 375 376 if (opts == null) { 377 opts = new Options(); 378 } 379 380 if (opts.inDensity == 0 && value != null) { 381 final int density = value.density; 382 if (density == TypedValue.DENSITY_DEFAULT) { 383 opts.inDensity = DisplayMetrics.DENSITY_DEFAULT; 384 } else if (density != TypedValue.DENSITY_NONE) { 385 opts.inDensity = density; 386 } 387 } 388 389 if (opts.inTargetDensity == 0 && res != null) { 390 opts.inTargetDensity = res.getDisplayMetrics().densityDpi; 391 } 392 393 return decodeStream(is, pad, opts); 394 } 395 396 /** 397 * Synonym for opening the given resource and calling 398 * {@link #decodeResourceStream}. 399 * 400 * @param res The resources object containing the image data 401 * @param id The resource id of the image data 402 * @param opts null-ok; Options that control downsampling and whether the 403 * image should be completely decoded, or just is size returned. 404 * @return The decoded bitmap, or null if the image data could not be 405 * decoded, or, if opts is non-null, if opts requested only the 406 * size be returned (in opts.outWidth and opts.outHeight) 407 */ 408 public static Bitmap decodeResource(Resources res, int id, Options opts) { 409 Bitmap bm = null; 410 InputStream is = null; 411 412 try { 413 final TypedValue value = new TypedValue(); 414 is = res.openRawResource(id, value); 415 416 bm = decodeResourceStream(res, value, is, null, opts); 417 } catch (Exception e) { 418 /* do nothing. 419 If the exception happened on open, bm will be null. 420 If it happened on close, bm is still valid. 421 */ 422 } finally { 423 try { 424 if (is != null) is.close(); 425 } catch (IOException e) { 426 // Ignore 427 } 428 } 429 430 if (bm == null && opts != null && opts.inBitmap != null) { 431 throw new IllegalArgumentException("Problem decoding into existing bitmap"); 432 } 433 434 return bm; 435 } 436 437 /** 438 * Synonym for {@link #decodeResource(Resources, int, android.graphics.BitmapFactory.Options)} 439 * will null Options. 440 * 441 * @param res The resources object containing the image data 442 * @param id The resource id of the image data 443 * @return The decoded bitmap, or null if the image could not be decode. 444 */ 445 public static Bitmap decodeResource(Resources res, int id) { 446 return decodeResource(res, id, null); 447 } 448 449 /** 450 * Decode an immutable bitmap from the specified byte array. 451 * 452 * @param data byte array of compressed image data 453 * @param offset offset into imageData for where the decoder should begin 454 * parsing. 455 * @param length the number of bytes, beginning at offset, to parse 456 * @param opts null-ok; Options that control downsampling and whether the 457 * image should be completely decoded, or just is size returned. 458 * @return The decoded bitmap, or null if the image data could not be 459 * decoded, or, if opts is non-null, if opts requested only the 460 * size be returned (in opts.outWidth and opts.outHeight) 461 */ 462 public static Bitmap decodeByteArray(byte[] data, int offset, int length, Options opts) { 463 if ((offset | length) < 0 || data.length < offset + length) { 464 throw new ArrayIndexOutOfBoundsException(); 465 } 466 467 Bitmap bm; 468 469 Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap"); 470 try { 471 bm = nativeDecodeByteArray(data, offset, length, opts); 472 473 if (bm == null && opts != null && opts.inBitmap != null) { 474 throw new IllegalArgumentException("Problem decoding into existing bitmap"); 475 } 476 setDensityFromOptions(bm, opts); 477 } finally { 478 Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); 479 } 480 481 return bm; 482 } 483 484 /** 485 * Decode an immutable bitmap from the specified byte array. 486 * 487 * @param data byte array of compressed image data 488 * @param offset offset into imageData for where the decoder should begin 489 * parsing. 490 * @param length the number of bytes, beginning at offset, to parse 491 * @return The decoded bitmap, or null if the image could not be decode. 492 */ 493 public static Bitmap decodeByteArray(byte[] data, int offset, int length) { 494 return decodeByteArray(data, offset, length, null); 495 } 496 497 /** 498 * Set the newly decoded bitmap's density based on the Options. 499 */ 500 private static void setDensityFromOptions(Bitmap outputBitmap, Options opts) { 501 if (outputBitmap == null || opts == null) return; 502 503 final int density = opts.inDensity; 504 if (density != 0) { 505 outputBitmap.setDensity(density); 506 final int targetDensity = opts.inTargetDensity; 507 if (targetDensity == 0 || density == targetDensity || density == opts.inScreenDensity) { 508 return; 509 } 510 511 byte[] np = outputBitmap.getNinePatchChunk(); 512 final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np); 513 if (opts.inScaled || isNinePatch) { 514 outputBitmap.setDensity(targetDensity); 515 } 516 } else if (opts.inBitmap != null) { 517 // bitmap was reused, ensure density is reset 518 outputBitmap.setDensity(Bitmap.getDefaultDensity()); 519 } 520 } 521 522 /** 523 * Decode an input stream into a bitmap. If the input stream is null, or 524 * cannot be used to decode a bitmap, the function returns null. 525 * The stream's position will be where ever it was after the encoded data 526 * was read. 527 * 528 * @param is The input stream that holds the raw data to be decoded into a 529 * bitmap. 530 * @param outPadding If not null, return the padding rect for the bitmap if 531 * it exists, otherwise set padding to [-1,-1,-1,-1]. If 532 * no bitmap is returned (null) then padding is 533 * unchanged. 534 * @param opts null-ok; Options that control downsampling and whether the 535 * image should be completely decoded, or just is size returned. 536 * @return The decoded bitmap, or null if the image data could not be 537 * decoded, or, if opts is non-null, if opts requested only the 538 * size be returned (in opts.outWidth and opts.outHeight) 539 */ 540 public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) { 541 // we don't throw in this case, thus allowing the caller to only check 542 // the cache, and not force the image to be decoded. 543 if (is == null) { 544 return null; 545 } 546 547 Bitmap bm = null; 548 549 Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap"); 550 try { 551 boolean decodeGenericStream = true; 552 if (is instanceof AssetManager.AssetInputStream) { 553 final int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); 554 bm = nativeDecodeAsset(asset, outPadding, opts); 555 // Do not follow the normal case. 556 decodeGenericStream = false; 557 } else if (is instanceof FileInputStream) { 558 try { 559 FileDescriptor fd = ((FileInputStream) is).getFD(); 560 // decodeFileDescriptor will take care of throwing the IAE and 561 // calling setDensityFromOptions. 562 return decodeFileDescriptor(fd, outPadding, opts); 563 } catch (IOException e) { 564 // Fall through to nativeDecodeStream. 565 } 566 } 567 568 if (decodeGenericStream) { 569 byte [] tempStorage = null; 570 if (opts != null) tempStorage = opts.inTempStorage; 571 if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE]; 572 bm = nativeDecodeStream(is, tempStorage, outPadding, opts); 573 } 574 575 if (bm == null && opts != null && opts.inBitmap != null) { 576 throw new IllegalArgumentException("Problem decoding into existing bitmap"); 577 } 578 579 setDensityFromOptions(bm, opts); 580 } finally { 581 Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); 582 } 583 584 return bm; 585 } 586 587 /** 588 * Decode an input stream into a bitmap. If the input stream is null, or 589 * cannot be used to decode a bitmap, the function returns null. 590 * The stream's position will be where ever it was after the encoded data 591 * was read. 592 * 593 * @param is The input stream that holds the raw data to be decoded into a 594 * bitmap. 595 * @return The decoded bitmap, or null if the image data could not be decoded. 596 */ 597 public static Bitmap decodeStream(InputStream is) { 598 return decodeStream(is, null, null); 599 } 600 601 /** 602 * Decode a bitmap from the file descriptor. If the bitmap cannot be decoded 603 * return null. The position within the descriptor will not be changed when 604 * this returns, so the descriptor can be used again as-is. 605 * 606 * @param fd The file descriptor containing the bitmap data to decode 607 * @param outPadding If not null, return the padding rect for the bitmap if 608 * it exists, otherwise set padding to [-1,-1,-1,-1]. If 609 * no bitmap is returned (null) then padding is 610 * unchanged. 611 * @param opts null-ok; Options that control downsampling and whether the 612 * image should be completely decoded, or just its size returned. 613 * @return the decoded bitmap, or null 614 */ 615 public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) { 616 Bitmap bm; 617 618 Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeFileDescriptor"); 619 try { 620 if (nativeIsSeekable(fd)) { 621 bm = nativeDecodeFileDescriptor(fd, outPadding, opts); 622 } else { 623 FileInputStream fis = new FileInputStream(fd); 624 // FIXME: If nativeDecodeStream grabbed the pointer to tempStorage 625 // from Options, this code would not need to be duplicated. 626 byte [] tempStorage = null; 627 if (opts != null) tempStorage = opts.inTempStorage; 628 if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE]; 629 try { 630 bm = nativeDecodeStream(fis, tempStorage, outPadding, opts); 631 } finally { 632 try { 633 fis.close(); 634 } catch (Throwable t) {/* ignore */} 635 } 636 } 637 638 if (bm == null && opts != null && opts.inBitmap != null) { 639 throw new IllegalArgumentException("Problem decoding into existing bitmap"); 640 } 641 642 setDensityFromOptions(bm, opts); 643 } finally { 644 Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); 645 } 646 return bm; 647 } 648 649 /** 650 * Decode a bitmap from the file descriptor. If the bitmap cannot be decoded 651 * return null. The position within the descriptor will not be changed when 652 * this returns, so the descriptor can be used again as is. 653 * 654 * @param fd The file descriptor containing the bitmap data to decode 655 * @return the decoded bitmap, or null 656 */ 657 public static Bitmap decodeFileDescriptor(FileDescriptor fd) { 658 return decodeFileDescriptor(fd, null, null); 659 } 660 661 private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage, 662 Rect padding, Options opts); 663 private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd, 664 Rect padding, Options opts); 665 private static native Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts); 666 private static native Bitmap nativeDecodeByteArray(byte[] data, int offset, 667 int length, Options opts); 668 private static native boolean nativeIsSeekable(FileDescriptor fd); 669} 670