BitmapFactory
  public
  
  
  
  class
  BitmapFactory
  
    extends Object
  
  
  
  
  
  
  
    
  Creates Bitmap objects from various sources, including files, streams,
 and byte-arrays.
Summary
| Nested classes | 
|---|
  
    
      | 
        
        
        
        
        class | BitmapFactory.Options 
        
    
 | 
    
    
| Public methods | 
|---|
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeByteArray(byte[] data, int offset, int length, BitmapFactory.Options opts)
      Decode an immutable bitmap from the specified byte array.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeByteArray(byte[] data, int offset, int length)
      Decode an immutable bitmap from the specified byte array.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeFile(String pathName, BitmapFactory.Options opts)
      Decode a file path into a bitmap.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeFile(String pathName)
      Decode a file path into a bitmap.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeFileDescriptor(FileDescriptor fd)
      Decode a bitmap from the file descriptor.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts)
      Decode a bitmap from the file descriptor.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeResource(Resources res, int id)
      Synonym for decodeResource(android.content.res.Resources, int, android.graphics.BitmapFactory.Options)with null Options. | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeResource(Resources res, int id, BitmapFactory.Options opts)
      Synonym for opening the given resource and calling
 decodeResourceStream(Resources, TypedValue, InputStream, Rect, Options). | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad, BitmapFactory.Options opts)
      Decode a new Bitmap from an InputStream.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeStream(InputStream is)
      Decode an input stream into a bitmap.
        
    
 | 
  
  
  
  
    | 
        
        
        static
        
        
        Bitmap | 
      decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts)
      Decode an input stream into a bitmap.
        
    
 | 
  
| Inherited methods | 
|---|
| 
    From class
      
        
          java.lang.Object
        
      
      
  
  
  
    | 
        
        
        
        
        
        Object | 
      clone()
      Creates and returns a copy of this object.
        
    
 |  
  
  
    | 
        
        
        
        
        
        boolean | 
      equals(Object obj)
      Indicates whether some other object is "equal to" this one.
        
    
 |  
  
  
    | 
        
        
        
        
        
        void | 
      finalize()
      Called by the garbage collector on an object when garbage collection
 determines that there are no more references to the object.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        Class<?> | 
      getClass()
      Returns the runtime class of this Object. |  
  
  
    | 
        
        
        
        
        
        int | 
      hashCode()
      Returns a hash code value for the object.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        void | 
      notify()
      Wakes up a single thread that is waiting on this object's
 monitor.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        void | 
      notifyAll()
      Wakes up all threads that are waiting on this object's monitor.
        
    
 |  
  
  
    | 
        
        
        
        
        
        String | 
      toString()
      Returns a string representation of the object.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        void | 
      wait(long timeoutMillis, int nanos)
      Causes the current thread to wait until it is awakened, typically
 by being notified or interrupted, or until a
 certain amount of real time has elapsed.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        void | 
      wait(long timeoutMillis)
      Causes the current thread to wait until it is awakened, typically
 by being notified or interrupted, or until a
 certain amount of real time has elapsed.
        
    
 |  
  
  
    | 
        
        
        
        final
        
        void | 
      wait()
      Causes the current thread to wait until it is awakened, typically
 by being notified or interrupted.
        
    
 |  | 
Public constructors
    BitmapFactory
    
public BitmapFactory ()
    
    
    
  
 
Public methods
    decodeByteArray
    
public static Bitmap decodeByteArray (byte[] data, 
                int offset, 
                int length, 
                BitmapFactory.Options opts)
    
    
    
  Decode an immutable bitmap from the specified byte array.
    
    | Parameters | 
|---|
      
        | data | byte: byte array of compressed image data | 
      
        | offset | int: offset into imageData for where the decoder should begin
               parsing. | 
      
        | length | int: the number of bytes, beginning at offset, to parse | 
      
        | opts | BitmapFactory.Options: null-ok; Options that control downsampling and whether the
             image should be completely decoded, or just is size returned. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image data could not be
         decoded, or, if opts is non-null, if opts requested only the
         size be returned (in opts.outWidth and opts.outHeight) | 
    
      
  
 
    decodeByteArray
    
public static Bitmap decodeByteArray (byte[] data, 
                int offset, 
                int length)
    
    
    
  Decode an immutable bitmap from the specified byte array.
    
    | Parameters | 
|---|
      
        | data | byte: byte array of compressed image data | 
      
        | offset | int: offset into imageData for where the decoder should begin
               parsing. | 
      
        | length | int: the number of bytes, beginning at offset, to parse | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image could not be decoded. | 
    
 
    decodeFile
    
public static Bitmap decodeFile (String pathName, 
                BitmapFactory.Options opts)
    
    
    
  Decode a file path into a bitmap. If the specified file name is null,
 or cannot be decoded into a bitmap, the function returns null.
    
    | Parameters | 
|---|
      
        | pathName | String: complete path name for the file to be decoded. | 
      
        | opts | BitmapFactory.Options: null-ok; Options that control downsampling and whether the
             image should be completely decoded, or just is size returned. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image data could not be
         decoded, or, if opts is non-null, if opts requested only the
         size be returned (in opts.outWidth and opts.outHeight) | 
    
      
  
 
    decodeFile
    
public static Bitmap decodeFile (String pathName)
    
    
    
  Decode a file path into a bitmap. If the specified file name is null,
 or cannot be decoded into a bitmap, the function returns null.
    
    | Parameters | 
|---|
      
        | pathName | String: complete path name for the file to be decoded. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | the resulting decoded bitmap, or null if it could not be decoded. | 
    
 
    decodeFileDescriptor
    
public static Bitmap decodeFileDescriptor (FileDescriptor fd)
    
    
    
  Decode a bitmap from the file descriptor. If the bitmap cannot be decoded
 return null. The position within the descriptor will not be changed when
 this returns, so the descriptor can be used again as is.
    
    | Parameters | 
|---|
      
        | fd | FileDescriptor: The file descriptor containing the bitmap data to decode | 
    
    
      | Returns | 
|---|
      
        | Bitmap | the decoded bitmap, or null | 
    
 
    decodeFileDescriptor
    
public static Bitmap decodeFileDescriptor (FileDescriptor fd, 
                Rect outPadding, 
                BitmapFactory.Options opts)
    
    
    
  Decode a bitmap from the file descriptor. If the bitmap cannot be decoded
 return null. The position within the descriptor will not be changed when
 this returns, so the descriptor can be used again as-is.
    
    | Parameters | 
|---|
      
        | fd | FileDescriptor: The file descriptor containing the bitmap data to decode | 
      
        | outPadding | Rect: If not null, return the padding rect for the bitmap if
                   it exists, otherwise set padding to [-1,-1,-1,-1]. If
                   no bitmap is returned (null) then padding is
                   unchanged. | 
      
        | opts | BitmapFactory.Options: null-ok; Options that control downsampling and whether the
             image should be completely decoded, or just its size returned. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | the decoded bitmap, or null | 
    
      
  
 
    decodeResource
    
public static Bitmap decodeResource (Resources res, 
                int id, 
                BitmapFactory.Options opts)
    
    
    
  Synonym for opening the given resource and calling
 decodeResourceStream(Resources, TypedValue, InputStream, Rect, Options).
    
    | Parameters | 
|---|
      
        | res | Resources: The resources object containing the image data | 
      
        | id | int: The resource id of the image data | 
      
        | opts | BitmapFactory.Options: null-ok; Options that control downsampling and whether the
             image should be completely decoded, or just is size returned. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image data could not be
         decoded, or, if opts is non-null, if opts requested only the
         size be returned (in opts.outWidth and opts.outHeight) | 
    
      
  
 
    decodeResourceStream
    
public static Bitmap decodeResourceStream (Resources res, 
                TypedValue value, 
                InputStream is, 
                Rect pad, 
                BitmapFactory.Options opts)
    
    
    
  Decode a new Bitmap from an InputStream. This InputStream was obtained from
 resources, which we pass to be able to scale the bitmap accordingly.
    
    | Parameters | 
|---|
      
        | res | Resources: This value may benull. | 
      
        | value | TypedValue: This value may benull. | 
      
        | is | InputStream: This value may benull. | 
      
        | pad | Rect: This value may benull. | 
      
        | opts | BitmapFactory.Options: This value may benull. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | This value may be null. | 
    
      
  
 
    
    
public static Bitmap decodeStream (InputStream is)
    
    
    
  Decode an input stream into a bitmap. If the input stream is null, or
 cannot be used to decode a bitmap, the function returns null.
 The stream's position will be where ever it was after the encoded data
 was read.
    
    | Parameters | 
|---|
      
        | is | InputStream: The input stream that holds the raw data to be decoded into a
           bitmap. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image data could not be decoded. | 
    
 
    
    
public static Bitmap decodeStream (InputStream is, 
                Rect outPadding, 
                BitmapFactory.Options opts)
    
    
    
  Decode an input stream into a bitmap. If the input stream is null, or
 cannot be used to decode a bitmap, the function returns null.
 The stream's position will be where ever it was after the encoded data
 was read.
    
    | Parameters | 
|---|
      
        | is | InputStream: The input stream that holds the raw data to be decoded into a
           bitmap.
 This value may benull. | 
      
        | outPadding | Rect: If not null, return the padding rect for the bitmap if
                   it exists, otherwise set padding to [-1,-1,-1,-1]. If
                   no bitmap is returned (null) then padding is
                   unchanged. | 
      
        | opts | BitmapFactory.Options: null-ok; Options that control downsampling and whether the
             image should be completely decoded, or just is size returned. | 
    
    
      | Returns | 
|---|
      
        | Bitmap | The decoded bitmap, or null if the image data could not be
         decoded, or, if opts is non-null, if opts requested only the
         size be returned (in opts.outWidth and opts.outHeight) | 
    
      
  
 
  
  
    
  
  
    
    
      
       
    
    
  
  
  Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
  Last updated 2025-02-10 UTC.
  
  
  
    
      [null,null,["Last updated 2025-02-10 UTC."],[],[]]