Android绘图相关类文档学习与翻译

来源:互联网 发布:淘宝优惠券兼职靠谱吗 编辑:程序博客网 时间:2024/05/31 18:31

前段时间的andengine自学计划完全泡汤感觉自己好无能。。。

现在要做个绘图板的项目,再一次决心好好弄。。。


下面是我整理的翻译内容,英文不好,刚过四级,大家海涵,欢迎纠错。

我觉得比较常用的方法我就会用红色字体标记了。

package

android.graphics

Provides low level graphics tools such as canvases, color filters, points,and rectangles that let you handle drawing to the screen directly.

 

提供低等级的图形工具,例如画布Canva,颜色过滤器ColorFilters,点Points,和矩形Rectangles。让你能够处理直接的在屏幕上绘图的任务。

中间有个percel的问题我不太理解,看了这位大神的博客懂了一些,链接:http://blog.csdn.net/niu_gao/article/details/6451699

还有位专门翻译研究文档的神人:http://www.cnblogs.com/over140/archive/2011/11/21/2256727.html

具体的文档可以参照http://developer.android.com/reference/android/graphics/Canvas.html#drawPaint(android.graphics.Paint)

我写的只是我自己的学习笔记,粗略一点简陋一点,我只是想记录下自己学了什么,提醒自己这个类有什么方法,需要用的时候还是要查文档的。

一个bitmap类还会涉及很多相关类,例如canvas、config等,我慢慢来。。。一定要弄完,不能像andengine学习计划一样被别的事情泡汤了

 

Interfaces


SurfaceTexture.OnFrameAvailableListener

Callback interface for being notified that a new stream frame is available. 

 

接口

一个新的流结构被通知的回调接口是可用的。

 

Bitmap类,位图

Public Methods

boolean

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

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

为制定的输出流写一个压缩版本的位图

 

 

 

 

 

 

 

 

 

 

Bitmap

copy(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.

根据一个已经有的位图创建一个新的位图,将新的位图设置为这个特定的位图的配置,并且复制这个位图的每一个像素到新的位图上去

 

 

 

 

 

 

 

 

 

 

void

copyPixelsFromBuffer(Buffer src)

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

从缓冲区复制像素,在最近的位置开始,覆盖位图的原有像素。

 

 

 

 

 

 

 

 

 

 

void

copyPixelsToBuffer(Buffer dst)

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

将位图的像素复制到特定的缓冲区中,(被调用者分配)。

 

 

 

 

 

 

 

 

 

 

static Bitmap

createBitmap(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 Bitmap

createBitmap(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.

这个方法和上一个方法一样。但是我不知道stride有什么含义。

 

 

 

 

 

 

 

 

 

 

static Bitmap

createBitmap(Bitmap source, int x, int y, int width, int height)

Returns an immutable bitmap from the specified subset of the source bitmap.

返回一个部件的位图对象,根据一个已经有的源位图,类似于复制方法,但是可以设定一些长宽参数等。

 

 

 

 

 

 

 

 

 

 

static Bitmap

createBitmap(Bitmap src)

Returns an immutable bitmap from the source bitmap.

基本内容同上一个方法。

 

 

 

 

 

 

 

 

 

 

static Bitmap

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

Returns a mutable bitmap with the specified width and height.

基本内容同上一个方法。

 

 

 

 

 

 

 

 

 

 

static Bitmap

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

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

返回一个位图,通过可选矩阵转化。这个方法我不太懂什么意思

 

 

 

 

 

 

 

 

 

 

static Bitmap

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

Returns a mutable bitmap with the specified width and height.

基本内容同上述方法。

 

 

 

 

 

 

 

 

 

 

static Bitmap

createBitmap(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 Bitmap

createBitmap(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 Bitmap

createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)

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

创建一个新的位图,从现有的位图缩放,当可能的情况下。

 

 

 

 

 

 

 

 

 

 

int

describeContents()

No special parcel contents.

没有特别的包裹内容。这个方法不知道到底是干什么用的。

 

 

 

 

 

 

 

 

 

 

void

eraseColor(int c)

Fills the bitmap's pixels with the specified Color.

将整个位图用特定的颜色填充。

 

 

 

 

 

 

 

 

 

 

Bitmap

extractAlpha()

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

返回一个捕获原始alpha值得位图。

 

 

 

 

 

 

 

 

 

 

Bitmap

extractAlpha(Paint paint, int[] offsetXY)

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

同上。

 

 

 

 

 

 

 

 

 

 

final int

getAllocationByteCount()

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

返回保存这个位图像素的内存的大小。

 

 

 

 

 

 

 

 

 

 

final int

getByteCount()

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

返回能够存储这个位图的内存的最小大小值。

 

 

 

 

 

 

 

 

 

 

final Bitmap.Config

getConfig()

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

如果这个位图内部的配置是在公有格式之一,那么返回这个配置,否则就返回null。

 

 

 

 

 

 

 

 

 

 

int

getDensity()

Returns the density for this bitmap.

返回这个位图的密度。

 

 

 

 

 

 

 

 

 

 

int

getGenerationId()

Returns the generation ID of this bitmap.

返回这个位图的识别ID。我是这样理解的。但是不太懂。

 

 

 

 

 

 

 

 

 

 

final int

getHeight()

Returns the bitmap's height

返回位图的高度。。。

 

 

 

 

 

 

 

 

 

 

byte[]

getNinePatchChunk()

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

返回一个私有数据的可选数组,被一些位图UI系统使用

 

 

 

 

 

 

 

 

 

 

int

getPixel(int x, int y)

Returns the Color at the specified location.

返回在特定位置的颜色。

 

 

 

 

 

 

 

 

 

 

void

getPixels(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.

得到位图中某一段的像素信息,存储在参数数组中。

 

 

 

 

 

 

 

 

 

 

final int

getRowBytes()

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

返回位图中每一行的像素个数

 

 

 

 

 

 

 

 

 

 

int

getScaledHeight(DisplayMetrics metrics)

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

方便地以DisplayMetrics的目标密度值调用getScaledHeight(int)

 

 

 

 

 

 

 

 

 

 

int

getScaledHeight(int targetDensity)

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

一个方便的,返回像素密度被整除后的位图高度值。参数是位图目标画布的高度

 

 

 

 

 

 

 

 

 

 

int

getScaledHeight(Canvas canvas)

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

方便地以Canvas的目标密度值调用getScaledHeight(int)

 

 

 

 

 

 

 

 

 

 

int

getScaledWidth(int targetDensity)

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

同上,宽度

 

 

 

 

 

 

 

 

 

 

int

getScaledWidth(DisplayMetrics metrics)

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

同上,宽度

 

 

 

 

 

 

 

 

 

 

int

getScaledWidth(Canvas canvas)

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

同上,宽度

 

 

 

 

 

 

 

 

 

 

final int

getWidth()

Returns the bitmap's width

得到一个位图的宽度

 

 

 

 

 

 

 

 

 

 

final boolean

hasAlpha()

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

得到一个位图的配置中,支持的每个像素的alpha值,如果像素能包含不透明的alpha值。

 

 

 

 

 

 

 

 

 

 

final boolean

hasMipMap()

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

这个真是不理解了,貌似设计到渲染方面的知识

 

 

 

 

 

 

 

 

 

 

final boolean

isMutable()

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

返回这个位图是否能够被改变。例如可以画

 

 

 

 

 

 

 

 

 

 

final boolean

isPremultiplied()

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

指示存储位图像素时候是否先预先乘以

 

 

 

 

 

 

 

 

 

 

final boolean

isRecycled()

Returns true if this bitmap has been recycled.

返回true如果位图已经被回收利用了

 

 

 

 

 

 

 

 

 

 

void

prepareToDraw()

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

重建关于位图的任意一个缓存,准备用来画图使用

 

 

 

 

 

 

 

 

 

 

void

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

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

重新配置一个位图的配置信息

 

 

 

 

 

 

 

 

 

 

void

recycle()

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

回收bitmap对象。类似于析构函数吧

 

 

 

 

 

 

 

 

 

 

boolean

sameAs(Bitmap other)

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

将这个bitmap的配置和参数中的bitmap配置统一,将本bitmap变成参数中的bitmap

 

 

 

 

 

 

 

 

 

 

void

setConfig(Bitmap.Config config)

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

方便的方法,调用reconfigure,用最近的高度和宽度

 

 

 

 

 

 

 

 

 

 

void

setDensity(int density)

Specifies the density for this bitmap.

指定位图的密度

 

 

 

 

 

 

 

 

 

 

void

setHasAlpha(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).

说明位图是否所有的像素都可以接受alpha值

 

 

 

 

 

 

 

 

 

 

final void

setHasMipMap(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.

这个方法我也不太懂,

 

 

 

 

 

 

 

 

 

 

void

setHeight(int height)

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

方便的方法,为了调用reconfigure方法,用最近的宽度和配置

 

 

 

 

 

 

 

 

 

 

void

setPixel(int x, int y, int color)

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

设置某个位置的像素的颜色

 

 

 

 

 

 

 

 

 

 

void

setPixels(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.

设置某一段像素的颜色

 

 

 

 

 

 

 

 

 

 

final void

setPremultiplied(boolean premultiplied)

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

设置,是否这个位图应该处理数据时候预先乘以,乘以什么我真是没搞明白

 

 

 

 

 

 

 

 

 

 

void

setWidth(int width)

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

方便的方法,用最近的高度和配置调用reconfigure方法

 

 

 

 

 

 

 

 

 

 

void

writeToParcel(Parcel p, int flags)

Write the bitmap and its pixels to the parcel.

将位图和它的像素打包。

 

 

 

 

 

 

 

 

 

 

 

 


0 0
原创粉丝点击