关于android:Bitmap-介绍详细版

0次阅读

共计 3677 个字符,预计需要花费 10 分钟才能阅读完成。

Bitmap 是 Android 应用程序中用来示意图像的类,提供了多种办法来操作和解决图像数据。上面是 Bitmap 类的全副办法介绍:

构造方法

Bitmap(int width, int height, Bitmap.Config config):创立一个指定宽度、高度和像素格局的空白 Bitmap 对象。

Bitmap(int width, int height, Bitmap.Config config, boolean isMutable):创立一个指定宽度、高度、像素格局和是否可变的空白 Bitmap 对象。

Bitmap(android.graphics.Bitmap source):将指定 Bitmap 对象的像素数据拷贝到新的 Bitmap 对象中。

Bitmap(android.graphics.Bitmap source, boolean isMutable):将指定 Bitmap 对象的像素数据拷贝到新的 Bitmap 对象中,同时指定是否可变。

Bitmap.createBitmap(int width, int height, Bitmap.Config config):创立一个指定宽度、高度和像素格局的空白 Bitmap 对象。

Bitmap.createBitmap(int[] colors, int offset, int stride, int width, int height, Bitmap.Config config):从给定的色彩数组中创立一个蕴含指定宽度、高度和像素格局的 Bitmap 对象。

Bitmap.createBitmap(android.graphics.Bitmap source, int x, int y, int width, int height):从指定 Bitmap 对象中截取一部分像素数据创立一个新的 Bitmap 对象。

Bitmap.createBitmap(android.graphics.Bitmap source, int x, int y, int width, int height, android.graphics.Matrix matrix, boolean filter):将指定 Bitmap 对象中的一部分像素数据利用指定的变换矩阵后创立一个新的 Bitmap 对象。

Bitmap.createBitmap(android.graphics.Bitmap source, int width, int height, android.graphics.Bitmap.Config config):将指定 Bitmap 对象缩放并创立一个新的 Bitmap 对象。

Bitmap.createScaledBitmap(android.graphics.Bitmap src, int dstWidth, int dstHeight, boolean filter):缩放指定 Bitmap 对象并返回一个新的 Bitmap 对象。

根本办法

copy(Bitmap.Config config, boolean isMutable):创立以后 Bitmap 对象的一份正本,正本的像素格局和可变性能够自定义。

copyPixelsFromBuffer(java.nio.Buffer src):从指定的 Buffer 中拷贝像素数据到以后 Bitmap 对象中。

copyPixelsToBuffer(java.nio.Buffer dst):将以后 Bitmap 对象中的像素数据拷贝到指定的 Buffer 中。

describeContents():不反对 Parcel 序列化,返回 0。

eraseColor(int color):应用指定的色彩填充以后 Bitmap 对象的所有像素。

extractAlpha():从以后 Bitmap 对象中提取蕴含 alpha 通道信息的新的 Bitmap 对象。

extractAlpha(Paint paint, int[] offset):从以后 Bitmap 对象中提取蕴含 alpha 通道信息的新的 Bitmap 对象,同时依照给定的 Paint 对象进行色彩过滤。

getAllocationByteCount():获取以后 Bitmap 对象所占用字节数(包含像素数据和内存治理开销等)。

getByteCount():获取以后 Bitmap 对象的像素数据占用字节数。

getConfig():获取以后 Bitmap 对象的像素格局。

getDensity():获取以后 Bitmap 对象的像素密度(DPI)。

getHeight():获取以后 Bitmap 对象的高度。

getWidth():获取以后 Bitmap 对象的宽度。

getNinePatchChunk():如果以后 Bitmap 对象是一个 NinePatch 暗影,则返回其对应的 chunk 数据,否则返回 null。

getPixel(int x, int y):获取以后 Bitmap 对象中指定地位的像素色彩值。

getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height):将以后 Bitmap 对象中指定区域的像素色彩值复制到给定的色彩数组中。

hasAlpha():判断以后 Bitmap 对象是否蕴含 alpha 通道信息。

isMutable():判断以后 Bitmap 对象是否可变。

isRecycled():判断以后 Bitmap 对象是否曾经被回收。

prepareToDraw():提醒零碎预加载以后 Bitmap 对象的像素数据,以进步绘制效率和性能。

recycle():回收以后 Bitmap 对象的内存空间,开释资源。

setDensity(int density):设置以后 Bitmap 对象的像素密度(DPI)。

setHasAlpha(boolean hasAlpha):设置以后 Bitmap 对象是否蕴含 alpha 通道信息。

setPixel(int x, int y, int color):设置以后 Bitmap 对象中指定地位的像素色彩值。

setPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height):将给定的色彩数组中的像素色彩值复制到以后 Bitmap 对象中指定区域的像素数据中。

压缩办法

compress(Bitmap.CompressFormat format, int quality, java.io.OutputStream stream):将以后 Bitmap 对象压缩成指定格局和品质的图像数据,并写入到给定的输入流中。

compress(Bitmap.CompressFormat format, int quality, java.nio.channels.WritableByteChannel channel):将以后 Bitmap 对象压缩成指定格局和品质的图像数据,并写入到给定的通道中。

compress(Bitmap.CompressFormat format, int quality, java.io.File file):将以后 Bitmap 对象压缩成指定格局和品质的图像数据,并写入到指定的文件中。

compress(Bitmap.CompressFormat format, int quality, java.lang.String fileName):将以后 Bitmap 对象压缩成指定格局和品质的图像数据,并写入到指定文件名的文件中。

高级办法

generateMipMap():生成以后 Bitmap 对象的一组 Mipmap,用于实现纹理映射等高级图形渲染性能。

generateMipMap(boolean canReuse):同上,但能够指定是否容许重用以后 Bitmap 对象来存储 Mipmap 数据。

getAllocation():获取以后 Bitmap 对象内存的 Allocation 对象(须要反对 RenderScript)。

getColorSpace():获取以后 Bitmap 对象的色彩空间信息(须要 API 26+ 反对)。

getGenerationId():获取以后 Bitmap 对象的版本号,用于判断对象是否被批改过。

getRowBytes():获取以后 Bitmap 对象的每行像素数据所占用的字节数。

reconfigure(int width, int height, Bitmap.Config config):重新配置以后 Bitmap 对象的宽度、高度和像素格局等属性。

setPixel(int x, int y, int color, int alphaType):同 setPixel(int x, int y, int color),但能够指定 alpha 通道类型。

setPremultiplied(boolean premultiplied):设置以后 Bitmap 对象是否预乘 alpha 值。

getWidth(int id):获取指定资源 ID 对应的 Bitmap 图像的宽度。

getHeight(int id):获取指定资源 ID 对应的 Bitmap 图像的高度。

以上就是 Bitmap 类的全副办法介绍,在理论开发中依据需要抉择适合的办法来操作 Bitmap 对象,能够实现很多乏味和有用的图像处理性能。

正文完
 0