Android Bitmap 常用方法

 

Public methods

booleancompress(Bitmap.CompressFormat format, int quality, OutputStream stream)

Write a compressed version of the bitmap to the specified outputstream.

Bitmapcopy(Bitmap.Config config, boolean isMutable)

Tries to make a new bitmap based on the dimensions of this bitmap, setting the new bitmap's config to the one specified, and then copying this bitmap's pixels into the new bitmap.

voidcopyPixelsFromBuffer(Buffer src)

 

Copy the pixels from the buffer, beginning at the current position, overwriting the bitmap's pixels.

voidcopyPixelsToBuffer(Buffer dst)

 

Copy the bitmap's pixels into the specified buffer (allocated by the caller).

static BitmapcreateBitmap(Bitmap source, int x, int y, int width, int height)

Returns a bitmap from the specified subset of the source bitmap.

static BitmapcreateBitmap(int[] colors, int width, int height, Bitmap.Config config)

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

static BitmapcreateBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)

Returns a bitmap from subset of the source bitmap, transformed by the optional matrix.

static BitmapcreateBitmap(DisplayMetrics display, int width, int height, Bitmap.Config config, boolean hasAlpha, ColorSpace colorSpace)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateBitmap(Bitmap src)

Returns a bitmap from the source bitmap.

static BitmapcreateBitmap(Picture source)

Creates a Bitmap from the given Picture source of recorded drawing commands.

static BitmapcreateBitmap(DisplayMetrics display, int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

static BitmapcreateBitmap(DisplayMetrics display, int[] colors, int width, int height, Bitmap.Config config)

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

static BitmapcreateBitmap(DisplayMetrics display, int width, int height, Bitmap.Config config)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)

Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.

static BitmapcreateBitmap(Picture source, int width, int height, Bitmap.Config config)

Creates a Bitmap from the given Picture source of recorded drawing commands.

static BitmapcreateBitmap(int width, int height, Bitmap.Config config, boolean hasAlpha, ColorSpace colorSpace)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateBitmap(DisplayMetrics display, int width, int height, Bitmap.Config config, boolean hasAlpha)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateBitmap(int width, int height, Bitmap.Config config)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateBitmap(int width, int height, Bitmap.Config config, boolean hasAlpha)

Returns a mutable bitmap with the specified width and height.

static BitmapcreateScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)

Creates a new bitmap, scaled from an existing bitmap, when possible.

intdescribeContents()

No special parcel contents.

voideraseColor(int c)

Fills the bitmap's pixels with the specified Color.

voideraseColor(long color)

Fills the bitmap's pixels with the specified ColorLong.

BitmapextractAlpha()

Returns a new bitmap that captures the alpha values of the original.

BitmapextractAlpha(Paint paint, int[] offsetXY)

Returns a new bitmap that captures the alpha values of the original.

intgetAllocationByteCount()

Returns the size of the allocated memory used to store this bitmap's pixels.

intgetByteCount()

Returns the minimum number of bytes that can be used to store this bitmap's pixels.

ColorgetColor(int x, int y)

Returns the Color at the specified location.

ColorSpacegetColorSpace()

Returns the color space associated with this bitmap.

Bitmap.ConfiggetConfig()

If the bitmap's internal config is in one of the public formats, return that config, otherwise return null.

intgetDensity()

 

Returns the density for this bitmap.

intgetGenerationId()

Returns the generation ID of this bitmap.

intgetHeight()

Returns the bitmap's height

byte[]getNinePatchChunk()

Returns an optional array of private data, used by the UI system for some bitmaps.

intgetPixel(int x, int y)

Returns the Color at the specified location.

voidgetPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)

Returns in pixels[] a copy of the data in the bitmap.

intgetRowBytes()

Return the number of bytes between rows in the bitmap's pixels.

intgetScaledHeight(int targetDensity)

Convenience method that returns the height of this bitmap divided by the density scale factor.

intgetScaledHeight(Canvas canvas)

Convenience for calling getScaledHeight(int) with the target density of the given Canvas.

intgetScaledHeight(DisplayMetrics metrics)

Convenience for calling getScaledHeight(int) with the target density of the given DisplayMetrics.

intgetScaledWidth(int targetDensity)

Convenience method that returns the width of this bitmap divided by the density scale factor.

intgetScaledWidth(DisplayMetrics metrics)

Convenience for calling getScaledWidth(int) with the target density of the given DisplayMetrics.

intgetScaledWidth(Canvas canvas)

Convenience for calling getScaledWidth(int) with the target density of the given Canvas.

intgetWidth()

Returns the bitmap's width

booleanhasAlpha()

Returns true if the bitmap's config supports per-pixel alpha, and if the pixels may contain non-opaque alpha values.

booleanhasMipMap()

Indicates whether the renderer responsible for drawing this bitmap should attempt to use mipmaps when this bitmap is drawn scaled down.

booleanisMutable()

Returns true if the bitmap is marked as mutable (i.e. can be drawn into)

booleanisPremultiplied()

 

Indicates whether pixels stored in this bitmaps are stored pre-multiplied.

booleanisRecycled()

Returns true if this bitmap has been recycled.

voidprepareToDraw()

Builds caches associated with the bitmap that are used for drawing it.

voidreconfigure(int width, int height, Bitmap.Config config)

 

Modifies the bitmap to have a specified width, height, and Config, without affecting the underlying allocation backing the bitmap.

voidrecycle()

Free the native object associated with this bitmap, and clear the reference to the pixel data.

booleansameAs(Bitmap other)

Given another bitmap, return true if it has the same dimensions, config, and pixel data as this bitmap.

voidsetColorSpace(ColorSpace colorSpace)

 

Modifies the bitmap to have the specified ColorSpace, without affecting the underlying allocation backing the bitmap.

voidsetConfig(Bitmap.Config config)

 

Convenience method for calling reconfigure(int, int, android.graphics.Bitmap.Config) with the current height and width.

voidsetDensity(int density)

 

Specifies the density for this bitmap.

voidsetHasAlpha(boolean hasAlpha)

Tell the bitmap if all of the pixels are known to be opaque (false) or if some of the pixels may contain non-opaque alpha values (true).

voidsetHasMipMap(boolean hasMipMap)

Set a hint for the renderer responsible for drawing this bitmap indicating that it should attempt to use mipmaps when this bitmap is drawn scaled down.

voidsetHeight(int height)

 

Convenience method for calling reconfigure(int, int, android.graphics.Bitmap.Config) with the current width and config.

voidsetPixel(int x, int y, int color)

 

Write the specified Color into the bitmap (assuming it is mutable) at the x,y coordinate.

voidsetPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)

 

Replace pixels in the bitmap with the colors in the array.

voidsetPremultiplied(boolean premultiplied)

Sets whether the bitmap should treat its data as pre-multiplied.

voidsetWidth(int width)

 

Convenience method for calling reconfigure(int, int, android.graphics.Bitmap.Config) with the current height and config.

static BitmapwrapHardwareBuffer(HardwareBuffer hardwareBuffer, ColorSpace colorSpace)

Create a hardware bitmap backed by a HardwareBuffer.

voidwriteToParcel(Parcel p, int flags)

Write the bitmap and its pixels to the parcel.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值