Lines Matching defs:bitmap
36 public final class Bitmap implements Parcelable {
37 private static final String TAG = "Bitmap";
40 * Indicates that the bitmap was created for an unknown pixel density.
42 * @see Bitmap#getDensity()
43 * @see Bitmap#setDensity(int)
47 // Estimated size of the Bitmap native allocation, not including
52 * Backing buffer for the Bitmap.
62 * Represents whether the Bitmap's content is requested to be pre-multiplied.
64 * isPremultiplied() may never return true for a 565 Bitmap or a bitmap
70 * The native bitmap's premultiplication state is kept up to date by
107 * Private constructor that must received an already allocated native bitmap
111 Bitmap(long nativeBitmap, byte[] buffer, int width, int height, int density,
115 throw new RuntimeException("internal error: native bitmap is 0");
136 Bitmap.class.getClassLoader(), nativeGetNativeFinalizer(), nativeSize);
148 * Native bitmap has been reconfigured, so set premult and cached
159 * <p>Returns the density for this bitmap.</p>
180 Log.w(TAG, "Called getDensity() on a recycle()'d bitmap! This is undefined behavior!");
186 * <p>Specifies the density for this bitmap. When the bitmap is
190 * @param density The density scaling factor to use with this bitmap or
203 * <p>Modifies the bitmap to have a specified width, height, and {@link
204 * Config}, without affecting the underlying allocation backing the bitmap.
205 * Bitmap pixel data is not re-initialized for the new configuration.</p>
207 * <p>This method can be used to avoid allocating a new bitmap, instead
208 * reusing an existing bitmap's allocation for a new configuration of equal
209 * or lesser size. If the Bitmap's allocation isn't large enough to support
211 * bitmap will not be modified.</p>
218 * the new bitmap will always be considered opaque. When converting from 565,
219 * the new bitmap will be considered non-opaque, and will respect the value
222 * <p>WARNING: This method should NOT be called on a bitmap currently in use
226 * system does not account for bitmap properties being modifying during use,
229 * <p>In order to safely ensure that a Bitmap is no longer in use by the
231 * invalidate()'ing any view that had previously drawn the Bitmap in the last
236 * final Bitmap myBitmap = ...;
252 checkRecycled("Can't call reconfigure() on a recycled bitmap");
329 * Free the native object associated with this bitmap, and clear the
332 * The bitmap is marked as "dead", meaning it will throw an exception if
335 * further uses for the bitmap. This is an advanced call, and normally need
337 * there are no more references to this bitmap.
345 // Bitmap itself is collected.
354 * Returns true if this bitmap has been recycled. If so, then it is an error
355 * to try to access its pixels, and the bitmap will not draw.
357 * @return true if the bitmap has been recycled
364 * Returns the generation ID of this bitmap. The generation ID changes
365 * whenever the bitmap is modified. This can be used as an efficient way to
366 * check if a bitmap has changed.
368 * @return The current generation ID for this bitmap.
372 Log.w(TAG, "Called getGenerationId() on a recycle()'d bitmap! This is undefined behavior!");
378 * This is called by methods that want to throw an exception if the bitmap
418 * Possible bitmap configurations. A bitmap configuration describes
462 * any bitmap created with this configuration will be created
497 * <p>Copy the bitmap's pixels into the specified buffer (allocated by the
502 * <p>The content of the bitmap is copied into the buffer as-is. This means
503 * that if this bitmap stores its pixels pre-multiplied
540 * overwriting the bitmap's pixels. The data in the buffer is not changed
542 * to whatever the bitmap's native format is.</p>
545 * the buffer. If you need to read the bitmap from the buffer again you must
549 checkRecycled("copyPixelsFromBuffer called on recycled bitmap");
579 * Tries to make a new bitmap based on the dimensions of this bitmap,
580 * setting the new bitmap's config to the one specified, and then copying
581 * this bitmap's pixels into the new bitmap. If the conversion is not
583 * bitmap initially has the same density as the original.
585 * @param config The desired config for the resulting bitmap
586 * @param isMutable True if the resulting bitmap should be mutable (i.e.
588 * @return the new bitmap, or null if the copy could not be made.
590 public Bitmap copy(Config config, boolean isMutable) {
591 checkRecycled("Can't copy a recycled bitmap");
592 Bitmap b = nativeCopy(mNativePtr, config.nativeInt, isMutable);
601 * Creates a new immutable bitmap backed by ashmem which can efficiently
606 public Bitmap createAshmemBitmap() {
607 checkRecycled("Can't copy a recycled bitmap");
608 Bitmap b = nativeCopyAshmem(mNativePtr);
617 * Creates a new immutable bitmap backed by ashmem which can efficiently
622 public Bitmap createAshmemBitmap(Config config) {
623 checkRecycled("Can't copy a recycled bitmap");
624 Bitmap b = nativeCopyAshmemConfig(mNativePtr, config.nativeInt);
633 * Creates a new bitmap, scaled from an existing bitmap, when possible. If the
635 * the source bitmap, the source bitmap is returned and no new bitmap is
638 * @param src The source bitmap.
639 * @param dstWidth The new bitmap's desired width.
640 * @param dstHeight The new bitmap's desired height.
642 * @return The new scaled bitmap or the source bitmap if no scaling is required.
645 public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight,
648 synchronized (Bitmap.class) {
663 Bitmap b = Bitmap.createBitmap(src, 0, 0, width, height, m, filter);
665 synchronized (Bitmap.class) {
676 * Returns an immutable bitmap from the source bitmap. The new bitmap may
678 * initialized with the same density as the original bitmap.
680 public static Bitmap createBitmap(Bitmap src) {
685 * Returns an immutable bitmap from the specified subset of the source
686 * bitmap. The new bitmap may be the same object as source, or a copy may
688 * bitmap.
690 * @param source The bitmap we are subsetting
695 * @return A copy of a subset of the source bitmap or the source bitmap itself.
697 * outside of the dimensions of the source bitmap, or width is <= 0,
700 public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) {
705 * Returns an immutable bitmap from subset of the source bitmap,
706 * transformed by the optional matrix. The new bitmap may be the
708 * initialized with the same density as the original bitmap.
710 * If the source bitmap is immutable and the requested subset is the
711 * same as the source bitmap itself, then the source bitmap is
712 * returned and no new bitmap is created.
714 * @param source The bitmap we are subsetting
723 * @return A bitmap that represents the specified subset of source
725 * outside of the dimensions of the source bitmap, or width is <= 0,
728 public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height,
734 throw new IllegalArgumentException("x + width must be <= bitmap.width()");
737 throw new IllegalArgumentException("y + height must be <= bitmap.height()");
749 Bitmap bitmap;
776 bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha());
787 bitmap = createBitmap(neww, newh, transformed ? Config.ARGB_8888 : newConfig,
800 // The new bitmap was created from a known bitmap source so assume that
802 bitmap.mDensity = source.mDensity;
803 bitmap.setHasAlpha(source.hasAlpha());
804 bitmap.setPremultiplied(source.mRequestPremultiplied);
806 canvas.setBitmap(bitmap);
810 return bitmap;
814 * Returns a mutable bitmap with the specified width and height. Its
817 * @param width The width of the bitmap
818 * @param height The height of the bitmap
819 * @param config The bitmap config to create.
822 public static Bitmap createBitmap(int width, int height, Config config) {
827 * Returns a mutable bitmap with the specified width and height. Its
830 * @param display Display metrics for the display this bitmap will be
832 * @param width The width of the bitmap
833 * @param height The height of the bitmap
834 * @param config The bitmap config to create.
837 public static Bitmap createBitmap(DisplayMetrics display, int width,
843 * Returns a mutable bitmap with the specified width and height. Its
846 * @param width The width of the bitmap
847 * @param height The height of the bitmap
848 * @param config The bitmap config to create.
849 * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the
850 * bitmap as opaque. Doing so will clear the bitmap in black
855 private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) {
860 * Returns a mutable bitmap with the specified width and height. Its
863 * @param display Display metrics for the display this bitmap will be
865 * @param width The width of the bitmap
866 * @param height The height of the bitmap
867 * @param config The bitmap config to create.
868 * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the
869 * bitmap as opaque. Doing so will clear the bitmap in black
874 private static Bitmap createBitmap(DisplayMetrics display, int width, int height,
879 Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
887 // No need to initialize the bitmap to zeroes with other configs;
894 * Returns a immutable bitmap with the specified width and height, with each
903 * @param width The width of the bitmap
904 * @param height The height of the bitmap
905 * @param config The bitmap config to create. If the config does not
911 public static Bitmap createBitmap(int colors[], int offset, int stride,
917 * Returns a immutable bitmap with the specified width and height, with each
921 * @param display Display metrics for the display this bitmap will be
928 * @param width The width of the bitmap
929 * @param height The height of the bitmap
930 * @param config The bitmap config to create. If the config does not
936 public static Bitmap createBitmap(DisplayMetrics display, int colors[],
952 Bitmap bm = nativeCreate(colors, offset, stride, width, height,
961 * Returns a immutable bitmap with the specified width and height, with each
967 * @param width The width of the bitmap
968 * @param height The height of the bitmap
969 * @param config The bitmap config to create. If the config does not
975 public static Bitmap createBitmap(int colors[], int width, int height, Config config) {
980 * Returns a immutable bitmap with the specified width and height, with each
984 * @param display Display metrics for the display this bitmap will be
988 * @param width The width of the bitmap
989 * @param height The height of the bitmap
990 * @param config The bitmap config to create. If the config does not
996 public static Bitmap createBitmap(DisplayMetrics display, int colors[],
1010 * Populates a rectangle with the bitmap's optical insets.
1029 * Specifies the known formats a bitmap can be compressed into
1049 * Write a compressed version of the bitmap to the specified outputstream.
1050 * If this returns true, the bitmap can be reconstructed by passing a
1052 * all Formats support all bitmap configs directly, so it is possible that
1053 * the returned bitmap from BitmapFactory could be in a different bitdepth,
1066 checkRecycled("Can't compress a recycled bitmap");
1074 Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "Bitmap.compress");
1082 * Returns true if the bitmap is marked as mutable (i.e. can be drawn into)
1096 * {@link Bitmap.Config#RGB_565}.</p>
1099 * {@link Bitmap.Config#ALPHA_8}.</p>
1102 * A bitmap with no alpha channel can be used both as a pre-multiplied and
1103 * as a non pre-multiplied bitmap.</p>
1106 * {@link Canvas}. If a non-pre-multiplied bitmap with an alpha channel is
1112 * @see Bitmap#setPremultiplied(boolean)
1117 Log.w(TAG, "Called isPremultiplied() on a recycle()'d bitmap! This is undefined behavior!");
1123 * Sets whether the bitmap should treat its data as pre-multiplied.
1127 * a Bitmap (through {@link #setPixel}, {@link #setPixels}, or {@link
1131 * <p>This method will not affect the behavior of a bitmap without an alpha
1135 * Bitmap whose colors are not pre-multiplied may result in a RuntimeException,
1139 * @see Bitmap#isPremultiplied()
1143 checkRecycled("setPremultiplied called on a recycled bitmap");
1148 /** Returns the bitmap's width */
1151 Log.w(TAG, "Called getWidth() on a recycle()'d bitmap! This is undefined behavior!");
1156 /** Returns the bitmap's height */
1159 Log.w(TAG, "Called getHeight() on a recycle()'d bitmap! This is undefined behavior!");
1197 * Convenience method that returns the width of this bitmap divided
1200 * @param targetDensity The density of the target canvas of the bitmap.
1201 * @return The scaled width of this bitmap, according to the density scale factor.
1208 * Convenience method that returns the height of this bitmap divided
1211 * @param targetDensity The density of the target canvas of the bitmap.
1212 * @return The scaled height of this bitmap, according to the density scale factor.
1231 * Return the number of bytes between rows in the bitmap's pixels. Note that
1232 * this refers to the pixels as stored natively by the bitmap. If you call
1237 * should not be used to calculate the memory usage of the bitmap. Instead,
1240 * @return number of bytes between rows of the native bitmap pixels.
1244 Log.w(TAG, "Called getRowBytes() on a recycle()'d bitmap! This is undefined behavior!");
1250 * Returns the minimum number of bytes that can be used to store this bitmap's pixels.
1253 * no longer be used to determine memory usage of a bitmap. See {@link
1262 * Returns the size of the allocated memory used to store this bitmap
1264 * <p>This can be larger than the result of {@link #getByteCount()} if a bitmap is reused to
1267 * #setConfig(Bitmap.Config)}, and {@link BitmapFactory.Options#inBitmap
1268 * BitmapFactory.Options.inBitmap}. If a bitmap is not modified in this way, this value will be
1271 * <p>This value will not change over the lifetime of a Bitmap.</p>
1285 * If the bitmap's internal config is in one of the public formats, return
1290 Log.w(TAG, "Called getConfig() on a recycle()'d bitmap! This is undefined behavior!");
1295 /** Returns true if the bitmap's config supports per-pixel alpha, and
1298 * alpha. However, for configs that do, the bitmap may be flagged to be
1305 Log.w(TAG, "Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!");
1311 * Tell the bitmap if all of the pixels are known to be opaque (false)
1316 * This is meant as a drawing hint, as in some cases a bitmap that is known
1321 checkRecycled("setHasAlpha called on a recycled bitmap");
1327 * bitmap should attempt to use mipmaps when this bitmap is drawn
1330 * If you know that you are going to draw this bitmap at less than
1344 Log.w(TAG, "Called hasMipMap() on a recycle()'d bitmap! This is undefined behavior!");
1350 * Set a hint for the renderer responsible for drawing this bitmap
1351 * indicating that it should attempt to use mipmaps when this bitmap
1354 * If you know that you are going to draw this bitmap at less than
1359 * allocate extra memory to hold the mipmap levels for this bitmap.
1370 checkRecycled("setHasMipMap called on a recycled bitmap");
1375 * Fills the bitmap's pixels with the specified {@link Color}.
1377 * @throws IllegalStateException if the bitmap is not mutable.
1380 checkRecycled("Can't erase a recycled bitmap");
1395 * @throws IllegalArgumentException if x, y exceed the bitmap's bounds
1399 checkRecycled("Can't call getPixel() on a recycled bitmap");
1405 * Returns in pixels[] a copy of the data in the bitmap. Each value is
1411 * @param pixels The array to receive the bitmap's colors
1414 * rows (must be >= bitmap's width). Can be negative.
1416 * the bitmap
1418 * the bitmap
1423 * bounds of the bitmap, or if abs(stride) < width.
1429 checkRecycled("Can't call getPixels() on a recycled bitmap");
1448 throw new IllegalArgumentException("x must be < bitmap.width()");
1451 throw new IllegalArgumentException("y must be < bitmap.height()");
1478 "x + width must be <= bitmap.width()");
1482 "y + height must be <= bitmap.height()");
1497 * <p>Write the specified {@link Color} into the bitmap (assuming it is
1503 * @param color The ARGB color to write into the bitmap
1505 * @throws IllegalStateException if the bitmap is not mutable
1506 * @throws IllegalArgumentException if x, y are outside of the bitmap's
1510 checkRecycled("Can't call setPixel() on a recycled bitmap");
1519 * <p>Replace pixels in the bitmap with the colors in the array. Each element
1523 * @param pixels The colors to write to the bitmap
1527 * the bitmap, but it can be larger (or negative).
1529 * the bitmap.
1531 * the bitmap.
1533 * @param height The number of rows to write to the bitmap
1535 * @throws IllegalStateException if the bitmap is not mutable
1537 * the bitmap's bounds.
1543 checkRecycled("Can't call setPixels() on a recycled bitmap");
1555 public static final Parcelable.Creator<Bitmap> CREATOR
1556 = new Parcelable.Creator<Bitmap>() {
1558 * Rebuilds a bitmap previously stored with writeToParcel().
1560 * @param p Parcel object to read the bitmap from
1561 * @return a new bitmap created from the data in the parcel
1563 public Bitmap createFromParcel(Parcel p) {
1564 Bitmap bm = nativeCreateFromParcel(p);
1566 throw new RuntimeException("Failed to unparcel Bitmap");
1570 public Bitmap[] newArray(int size) {
1571 return new Bitmap[size];
1583 * Write the bitmap and its pixels to the parcel. The bitmap can be
1585 * @param p Parcel object to write the bitmap data into
1588 checkRecycled("Can't parcel a recycled bitmap");
1595 * Returns a new bitmap that captures the alpha values of the original.
1599 * @return new bitmap containing the alpha channel of the original bitmap.
1602 public Bitmap extractAlpha() {
1607 * Returns a new bitmap that captures the alpha values of the original.
1610 * could change the actual dimensions of the resulting bitmap (e.g.
1611 * a blur maskfilter might enlarge the resulting bitmap). If offsetXY
1612 * is not null, it returns the amount to offset the returned bitmap so
1615 * -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then
1619 * <p>The initial density of the returned bitmap is the same as the original's.
1622 * resulting bitmap. Pass null for default behavior.
1624 * (index 1) offset needed to position the returned bitmap
1626 * @return new bitmap containing the (optionally modified by paint) alpha
1627 * channel of the original bitmap. This may be drawn with
1632 public Bitmap extractAlpha(Paint paint, int[] offsetXY) {
1633 checkRecycled("Can't extractAlpha on a recycled bitmap");
1635 Bitmap bm = nativeExtractAlpha(mNativePtr, nativePaint, offsetXY);
1637 throw new RuntimeException("Failed to extractAlpha on Bitmap");
1644 * Given another bitmap, return true if it has the same dimensions, config,
1645 * and pixel data as this bitmap. If any of those differ, return false.
1648 public boolean sameAs(Bitmap other) {
1649 bitmap!");
1653 throw new IllegalArgumentException("Can't compare to a recycled bitmap!");
1659 * Rebuilds any caches associated with the bitmap that are used for
1662 * If this is called on more than one bitmap in sequence, the priority is
1663 * given in LRU order (i.e. the last bitmap called will be given highest
1673 checkRecycled("Can't prepareToDraw on a recycled bitmap!");
1682 checkRecycled("Can't refSkPixelRef on a recycled bitmap!");
1688 private static native Bitmap nativeCreate(int[] colors, int offset,
1691 private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig,
1693 private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap);
1694 private static native Bitmap nativeCopyAshmemConfig(long nativeSrcBitmap, int nativeConfig);
1722 private static native Bitmap nativeCreateFromParcel(Parcel p);
1728 // returns a new bitmap built from the native bitmap's alpha, and the paint
1729 private static native Bitmap nativeExtractAlpha(long nativeBitmap,