bitmap drawablebmp = new Bitmap("1.gif"); 报错:未能找到文件...

Bitmap与Bitmapdata - 醒着/☆☆ - 博客园
一个 Bitmap 对象可在若干 Bitmap 对象之中共享其 BitmapData 引用,与转换属性或旋转属性无关。由于能够创建引用相同 BitmapData 对象的多个 Bitmap 对象,因此,多个显示对象可以使用相同的复杂 BitmapData 对象,而不会因为每个显示对象实例使用一个 BitmapData 对象而产生内存开销。
示例1:创建500个位图,每个位图使用不同引用的BitmapData的内存
import flash.display.BitmapD
import flash.display.B
import flash.system.S
//打印初始的内存情况
trace("开始空闲时内存: "+System.totalMemory/1000+"k");
var bmpdt:BitmapD
for(var i:int=0;i&500;i++)
//每次都是新的bitmapData给bitmap
bmpdt=new BitmapData(100,100,false,0xffccdd);
var bmp:Bitmap=new Bitmap(bmpdt);
addChild(bmp)
bmp.x=i+3;
bmp.y=i+3;
trace("创建完毕后内存: "+System.totalMemory/1000+"k");
结果:开始空闲时内存: k创建完毕后内存: k
示例2:创建500个位图,每个位图使用了同一个BitmapData的引用
import flash.display.BitmapD
import flash.display.B
import flash.system.S
//打印初始的内存情况
trace("开始空闲时内存: "+System.totalMemory/1000+"k");
var bmpdt:BitmapData=new BitmapData(100,100,false,0xffccdd);;
for(var i:int=0;i&500;i++)
var bmp:Bitmap=new Bitmap(bmpdt);
addChild(bmp)
bmp.x=i+3;
bmp.y=i+3;
trace("创建完毕后内存: "+System.totalMemory/1000+"k");
结果:开始空闲时内存: k创建完毕后内存: k
像素贴紧和平滑
bmp.smoothing=位图缩放时 会模糊 。使用 Bitmap.smoothing=会让图像更平滑自然,也会更加消耗性能应用滤镜在将 smoothing 设置为 true 的情况下绘制位图要比在将 smoothing 设置为 false 的情况下执行相同操作更为缓慢。
import flash.display.BitmapD
import flash.geom.R
import flash.geom.P
import flash.filters.BlurF
import flash.display.B
//创建bitmapData
var bmpdt:BitmapData=new BitmapData(80,30,false,0xffccdd);
//创建一个Rectangle 这个rect会指定到bitmapdata的坐标上
var rect:Rectangle=new Rectangle(20,10,40,10);
//对这个区域 填充颜色
bmpdt.fillRect(rect,0x0033ff);
//获取这个矩形的左上角坐标
var pt:Point=new Point(rect.left,rect.top);
var blFilter:BlurFilter=new BlurFilter(8,8,1);
bmpdt.applyFilter(bmpdt,rect,pt,blFilter);
var bmp:Bitmap=new Bitmap(bmpdt);
addChild(bmp);
滤镜滤镜和位图缓存:若要对显示对象应用滤镜,必须启用该对象的位图缓存。在对 cacheAsBitmap 属性设置为false 的显示对象应用滤镜时,Flash Player 会自动将该对象的 cacheAsBitmap 属性的值设置为 true。如果您以后删除了该显示对象中的所有滤镜,Flash Player 会将 cacheAsBitmap 属性重置为最后设置的值。在运行时更改滤镜:如果已经对显示对象应用了一个或多个滤镜,则无法向 filters 属性数组添加其它滤镜。若要添加或更改应用的这组滤镜,需要创建整个滤镜数组的副本,然后对此(临时)数组进行修改。然后,将此数组重新分配给显示对象的 filters 属性,这样才能将滤镜应用于该对象。滤镜示例:
var bmpdt:BitmapData=new BitmapData(100,100,true,0xffccddee);
var bmp:Bitmap=new Bitmap(bmpdt);
addChild(bmp);
var filter:BlurFilter=new BlurFilter(10,10,1);
//声明一个rectangel 坐标是绝对坐标和区域
var rect:Rectangle=new Rectangle(50,50,50,50);
var p:Point=new Point(50,50);
//必须有填充色 否则滤镜无效
bmpdt.fillRect(rect,0xffFF0000);
bmpdt.applyFilter(bmpdt,rect,p,filter);
colorTransform示例:
var bmd1:BitmapData = new BitmapData(100,100,true,0xffffccdd);
var bmp:Bitmap=new Bitmap(bmd1);
addChild(bmp);
var clorTran:ColorTransform=new ColorTransform();
//颜色转换 透明度设置0.7
clorTran.alphaMultiplier=0.7;
var rect:Rectangle=new Rectangle(50,50,20,20);
//对 Bitmapdata设置colorTranform
bmd1.colorTransform(rect,clorTran);
import flash.display.B
import flash.display.BitmapD
import flash.geom.R
import flash.geom.P
//目标Bitmapdata 待被复制
var bmd1:BitmapData = new BitmapData(40, 40, false, 0x000000FF);
var bmd2:BitmapData = new BitmapData(80, 40, false, 0x0000CC44);
//原始Bitmapdata打个标记
bmd1.setPixel(15,15,0x00ff0000);
var rect:Rectangle = new Rectangle(10, 10, 10, 10);
var pt:Point = new Point(30, 10);
//从Bitmapdata源的rect区域复制到 pt里
bmd2.copyPixels(bmd1, rect, pt);
var bm1:Bitmap = new Bitmap(bmd1);
this.addChild(bm1);
var bm2:Bitmap = new Bitmap(bmd2);
this.addChild(bm2);
bm2.x = 50;
draw()BitmapData.draw(source:IBitmapDrawable):voidDisplayObject 和 BitmapData 类实现了 IBitmapDrawable接口
floodFill类似Flash工具里的油漆桶
var bmpdt:BitmapData=new BitmapData(200,200,false,0xff0000);
var rect:Rectangle=new Rectangle(0,0,100,100);
bmpdt.fillRect(rect,0x00ff00);
rect.x=50;
rect.y=50;
bmpdt.fillRect(rect,0x0000ff);
rect.x=100;
rect.y=100;
bmpdt.fillRect(rect,0xff00ff);
//floodFill相当于油漆桶倾倒功能
bmpdt.floodFill(90,90,0xffccee)
var bmp:Bitmap=new Bitmap(bmpdt);
addChild(bmp);
getPixels(rectangle)从像素数据的矩形区域生成一个字节数组。为每个像素将一个无符号整数(32 位未经相乘的像素值)写入字节数组。
import flash.display.BitmapD
import flash.geom.R
import flash.display.B
import flash.utils.ByteA
var bmd:BitmapData = new BitmapData(a.width, a.height, true);
bmd.draw(a);
var bounds:Rectangle = new Rectangle(0, 0, bmd.width, bmd.height);
//BitmapData.getPixels(rectangel):ByteArray 获取图像数据的一个Rectangle的二进制数据
var pixels:ByteArray = bmd.getPixels(bounds);
trace(pixels)
//&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O& &O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O& &&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&& &O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O&&O&O&O& &&O&O&O&&O&O&O&&?3&&?3&&?3&&?3&&?3&&?3&&?& 3&&?3&&?3&&?3&&?3&&?3&&?3&&?3&&?3&&?3&&?& 3&&?3&&?1379人阅读
Eclipse Memory Analyzer并不提供从一个bitmap buffer直接观察图片内容的功能,下面的步骤教你从bitmap buffer中导出一个我们能够直接浏览的图片:
1. 存储要浏览的bitmap buffer
2. 将bitmap buffer存到本地电脑中
输入或选择要存放图片的本地路径
3. 在Eclipse中打开inspector视图
当你要将存好的bitmap buffer转换成普通图片时,需要知道bitmap所对应图片的宽高,从inspector视图中可以得到。
4. 从inspector视图中找到bitmap的宽高
5. 将bitmap buffer文件转换为bmp图片文件
import java.io.ByteArrayOutputS
import java.io.DataOutputS
import java.io.F
import java.io.FileInputS
import java.io.FileOutputS
import java.io.InputS
import java.io.OutputS
import java.nio.ByteB
import java.nio.ByteO
import java.util.A
public class MATBitmap {
/* Constants */
public static final int RMASK = 0x00ff0000;
public static final int GMASK = 0x0000ff00;
public static final int BMASK = 0x000000
public static final int AMASK = 0xff000000;
private static final int SIZE_OF_HEADER = 12;
private static final int SIZE_OF_DIB_HEADER = 108;
private static final int SIZE_OF_MAGIC = 2;
/* Structures */
class bmpfile_magic {
byte magic[];
static class BMPFile_header {
short creator1;
short creator2;
public byte[] getBytes() {
ByteBuffer out = ByteBuffer.allocate(SIZE_OF_HEADER);
out.order(ByteOrder.LITTLE_ENDIAN);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bout);
out.putInt(filesz);
out.putShort(creator1);
out.putShort(creator2);
out.putInt(bmp_offset);
return out.array();
} catch (Exception e) {
static class BMPFile_dibheader {
int header_
int compress_
int rmask, gmask, bmask,
int colorspace_
byte[] colorspace = new byte[0x24];
int rgamma, ggamma,
public byte[] getBytes() {
ByteBuffer out = ByteBuffer.allocate(SIZE_OF_DIB_HEADER);
out.order(ByteOrder.LITTLE_ENDIAN);
out.putInt(header_sz);
out.putInt(width);
out.putInt(height);
out.putShort(nplanes);
out.putShort(bitspp);
out.putInt(compress_type);
out.putInt(bmp_bytesz);
out.putInt(hres);
out.putInt(vres);
out.putInt(ncolors);
out.putInt(nimpcolors);
out.putInt(rmask);
out.putInt(gmask);
out.putInt(bmask);
out.putInt(amask);
out.putInt(colorspace_type);
out.put(colorspace);
out.putInt(rgamma);
out.putInt(ggamma);
out.putInt(bgamma);
return out.array();
} catch(Exception e) {
e.printStackTrace();
/* Displays usage info and exits */
private static void usage() {
System.out
.println(&Usage:\t%s &img_src& &img_dest.bmp& &width& &height&\n&
+ &\timg_src:\timage byte buffer obtained from Eclipse MAT, using 'copy & save value to file' while selecting the byte[] buffer corresponding to an android.graphics.Bitmap\n&
+ &\timg_dest:\tpath to target *.bmp file\n&
+ &\twidth:\t\tpicture width, obtained in Eclipse MAT, selecting the android.graphics.Bitmap object and seeing the object member values\n&
+ &\theight:\t\tpicture height\n\n&);
System.exit(0);
/* C entry point */
public static void main(String[] args) {
args = new String[4];
args[0] = &c:/0x100.png&;
args[1] = &c:/conv1.bmp&;
args[2] = &512&;
args[3] = &512&;
FileInputS
FileOutputS
String file_in, file_
int w, h, W, H;
byte r, g, b, a, image[];
byte[] magic = new byte[2];
BMPFile_header header = new BMPFile_header();
BMPFile_dibheader dibheader = new BMPFile_dibheader();
/* Parse command line */
if (args.length != 4) {
file_in = args[0];
file_out = args[1];
W = Integer.parseInt(args[2]);
H = Integer.parseInt(args[3]);
in = new FileInputStream(file_in);
out = new FileOutputStream(file_out);
/* Check parameters */
if (in == null || out == null || W == 0 || H == 0) {
/* Init BMP headers */
magic[0] = 'B';
magic[1] = 'M';
header.filesz = W * H * 4 + magic.length + SIZE_OF_HEADER
+ SIZE_OF_DIB_HEADER;
header.creator1 = 0;
header.creator2 = 0;
header.bmp_offset = SIZE_OF_MAGIC + SIZE_OF_HEADER
+ SIZE_OF_DIB_HEADER;
dibheader.header_sz = SIZE_OF_DIB_HEADER;
dibheader.width = W;
dibheader.height = H;
dibheader.nplanes = 1;
dibheader.bitspp = 32;
press_type = 3;
dibheader.bmp_bytesz = W * H * 4;
dibheader.hres = 2835;
dibheader.vres = 2835;
dibheader.ncolors = 0;
dibheader.nimpcolors = 0;
dibheader.rmask = RMASK;
dibheader.gmask = BMASK;
dibheader.bmask = GMASK;
dibheader.amask = AMASK;
dibheader.colorspace_type = 0x57696e20;
Arrays.fill(dibheader.colorspace, (byte)0);
dibheader.rgamma = dibheader.bgamma = dibheader.ggamma = 0;
/* Read picture data */
image = new byte[4 * W * H];
if (image == null) {
System.out.println(&Could not allocate a %d-byte buffer. : &
+ (4 * W * H));
System.exit(0);
in.read(image);
in.close();
/* Write header */
out.write(magic);
out.write(header.getBytes());
out.write(dibheader.getBytes());
System.out.println(&Started writing&);
/* Convert the byte array to BMP format */
ByteArrayOutputStream bout = new ByteArrayOutputStream();
for (h = H - 1; h &= 0; h--) {
for (w = 0; w & W; w++) {
r = image[w * 4 + 4 * W * h];
b = image[w * 4 + 4 * W * h + 1];
g = image[w * 4 + 4 * W * h + 2];
a = image[w * 4 + 4 * W * h + 3];
bout.write(b);
bout.write(g);
bout.write(r);
bout.write(a);
out.write(bout.toByteArray());
bout.close();
System.out.println(&Finishe writing&);
out.close();
} catch (Exception e) {
e.printStackTrace();
将上面java代码存为MATBitmap.java,然后将该java文件与本地存储的buffer文件存到同一目录下,随后在该目录中调起命令行采用下列格式执行命令:
Java MATBitmap.java &input.bmp& &output.bmp& &bitmap width& &bitmap height&
java MATBitmap debug.bmp converted.bmp 800 800
然后就可以用普通图片浏览器观察定位该bitmap文件了,从而可以定位内存中未释放的资源
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:118887次
积分:1467
积分:1467
排名:第15391名
原创:19篇
转载:23篇
评论:23条
(1)(1)(2)(17)(22)Android位图操作 - 1.曲待续 - 博客园
随笔 - 309, 文章 - 0, 评论 - 5, 引用 - 0
Bitmap是系统中的图像处理的最重要类之一。用它可以获取图像文件信息,进行图像剪切、旋转、缩放等操作,并可以指定格式保存图像文件。对Android用户界面的设计,和对于Android
UI开发自绘控件和游戏制作而言掌握好位图基础是必不可少的。本次主要涉及以下的相关内容。本文从应用的角度,着重介绍怎么用Bitmap来实现这些功能。
一、位图主要操作步骤
(一)获取图片
(1).通过
BitmapDrawable 方式得到 Bitmap
InputStream is =res.openRawResource(R.drawable.picture);
BitmapDrawable bmpDraw= new BitmapDrawable(is);
Bitmap bmp =bmpDraw.getBitmap();
或BitmapDrawable bmpDraw =(BitmapDrawable)res.getDrawable(R.drawable.picture);
从资源文件中装载图片 */
//getResources()-&得到Resources
//getDrawable()-&得到资源中的Drawable对象,参数为资源索引ID
//getBitmap()-&得到Bitmap
mBitQQ =((BitmapDrawable) getResources().getDrawable
(R.drawable.qq)).getBitmap();
Bitmap bmp =bmpDraw.getBitmap();
(2).通过
BitmapFactory 得到 Bitmap
Bitmap bmp =BitmapFactory.decodeResource(res, R.drawable.picture);
BitmapFactory
可以通过资源ID、路径、文件、数据流等方式来获取位图。
可支持的图片格式如下:png、jpg、gif、bmp
//从资源文件中装载图片&getResources()-&得到Resources
//BitmapFactory
可以通过图像文件来获取位图
mBitmapTop = BitmapFactory.decodeResource(getResources(),R.drawable.desktop);
(3)用createBitmap(w,h,
Config.ARGB_8888) 得到屏幕上指定区域的位图
&&&&& int w = 240,h = 120;
String mstrTitle = &感受Android带给我们的新体验&;
&&& mbmpTest = Bitmap.createBitmap(w,h,Config.ARGB_8888);
Canvas canvasTemp = new Canvas(mbmpTest);
canvasTemp.drawColor(Color.WHITE);
Paint p = new Paint();
String familyName = &宋体&;
Typeface font = Typeface.create(familyName,Typeface.BOLD);
p.setColor(Color.RED);
p.setTypeface(font);
p.setTextSize(17);
canvasTemp.drawText(mstrTitle,0,30,p);
p.setColor(Color.YELLOW);
canvasTemp.drawRect(100,40,200,110, p);
canvas.drawBitmap(mbmpTest, 0, 180,
null);&&&&&&
(二)位图显示
显示到画布上:
Canvas 画布 drawbitmap
/* 在屏幕(left,top)处开始显示图片bitmap
&canvas.drawbitmap(Bitmap bitmap, float left,float top, Paint paint);
BitmapDrawable 绘制该图片到控件上&&
//bitmap.draw(canvas);
转换为BitmapDrawable对象显示位图
&&&&&&& Bitmapbmp=BitmapFactory.decodeResource(res, R.drawable.pic180);
&&&&&&& // 转换为BitmapDrawable对象
&&&&&&& BitmapDrawable bmpDraw=new BitmapDrawable(bmp);
&&&&&&& // 显示位图
&&&&&&& ImageView iv2 =(ImageView)findViewById(R.id.ImageView02);
&&&&&& iv2.setImageDrawable(bmpDraw);
(三)位图缩放
(1)重画位图
drawBitmap(Bitmapbitmap, Rect src, Rect dst, Paint paint)
(2)缩放原位图,创建一个新的位图
createBitmap(Bitmapsource, int x, int y, int width, int height, Matrix m, boolean filter)
(3)scale&
Canvas的 scale(float sx, floatsy)
不过要注意此时整个画布都缩放了
(4)用Matrix实现位图缩放
Matrix matrix=newMatrix();
matrix.postScale(0.2f, 0.2f);
Bitmapbmp=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,t rue);
用Matrix实现
Bitmap bmp =BitmapFactory.decodeResource(getResources(), R.drawable.pic180);
Matrix matrix=newMatrix();
matrix.postRotate(45);
Bitmapdstbmp=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true);
canvas.drawColor(Color.BLACK);
二、位图主要概念
&android.content.res
& android.graphics& 底层图形类
android.content.res.Resources
对于Android平台的资源类android.content.res.Resources可能很多网友比较陌生,一起来看看SDK上是怎么介绍的吧,Contains
classes foraccessing application resources, such as raw asset files, colors, drawables,media or other other files in the package, plus important device configurationdetails (orientation, input types, etc.) that affect how the application maybehave.平时用到的二进制源文件raw、颜色colors、图形drawables和多媒体文件media的相关资源均通过该类来管理。
& int&getColor(int id)&
对应res/values/colors.xml
& Drawable&getDrawable(int id)&
对应res/drawable/
&XmlResourceParser& getLayout(int id)&
对应res/layout/
& String&getString(int id)
和CharSequence&getText(int id)&&
对应res/values/strings.xml
&InputStream& openRawResource(int id)&
对应res/raw/
& voidparseBundleExtra (String tagName, AttributeSet attrs, Bundle outBundle)
对应res/xml/
& String[]&getStringArray(int id)& res/values/arrays.xml
& float&getDimension(int id)& res/values/dimens.xml
&(二)android.graphics.Bitmap
作为位图操作类,Bitmap提供了很多实用的方法,常用的我们总结如下:
& boolean& pressFormat format, int quality,OutputStream stream)
压缩一个Bitmap对象根据相关的编码、画质保存到一个OutputStream中。其中第一个压缩格式目前有JPG和PNG
& void& copyPixelsFromBuffer(Buffer src) 从一个Buffer缓冲区复制位图像素
& void& copyPixelsToBuffer(Buffer dst)& 将当前位图像素内容复制到一个Buffer缓冲区
我们看到创建位图对象createBitmap包含了6种方法在目前的Android
2.1 SDK中,当然他们使用的是API Level均为1,所以说从Android
1.0 SDK开始就支持了,所以大家可以放心使用。
&&staticBitmap& createBitmap(Bitmap src)
&static Bitmap& createBitmap(int[] colors, int width, int height,Bitmap.Config config)
&static Bitmap& createBitmap(int[] colors, int offset, int stride,int width, int height, Bitmap.Config config)
&static Bitmap& createBitmap(Bitmap source, int x, int y, int width,int height, Matrix m, boolean filter)
&static Bitmap& createBitmap(int width, int height, Bitmap.Configconfig)
&static Bitmap& createBitmap(Bitmap source, int x, int y, int width,int height)
&static Bitmap& createScaledBitmap(Bitmap src, int dstWidth, intdstHeight, boolean filter)& //创建一个可以缩放的位图对象
&final int&getHeight()&
&final int& getWidth()&& 获取宽度
&final boolean& hasAlpha()&& 是否有透明通道
&void& setPixel(int x, int y, int color)&& 设置某像素的颜色
&int& getPixel(int x, int y)& 获取某像素的颜色,android开发网提示这里返回的int型是color的定义
android.graphics.BitmapFactory
Bitmap实现在.graphics包中。但是Bitmap类的构造函数是私有的,外面并不能实例化,只能是通过JNI实例化。这必然是某个辅助类提供了创建Bitmap的接口,而这个类的实现通过JNI接口来实例化Bitmap的,这个类就是BitmapFactory。&
作为Bitmap对象的I/O类,BitmapFactory类提供了丰富的构造Bitmap对象的方法,比如从一个字节数组、文件系统、资源ID、以及输入流中来创建一个Bitmap对象,下面本类的全部成员,除了decodeFileDescriptor外其他的重载方法都很常用。
static Bitmap&decodeByteArray(byte[] data, int offset, int length) //从字节数组创建
static Bitmap&decodeByteArray(byte[] data, int offset, int length, BitmapFactory.Optionsopts)
static Bitmap&decodeFile(String pathName, BitmapFactory.Options opts) //从文件创建,路径要写全
static Bitmap&decodeFile(String pathName)
static Bitmap&decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Optionsopts)& //从输入流句柄创建
static Bitmap&decodeFileDescriptor(FileDescriptor fd)
static Bitmap&decodeResource(Resources res, int id)& //从Android的APK文件资源中创建,android123提示是从/res/的drawable中
static Bitmap&decodeResource(Resources res, int id, BitmapFactory.Options opts)
static Bitmap&decodeResourceStream(Resources res, TypedValue value, InputStream is, Rect pad,BitmapFactory.Options opts)
static Bitmap&decodeStream(InputStream is)& //从一个输入流中创建
static Bitmap&decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts)
android.graphics.Canvas
从J2ME MIDLET时我们就知道Java提供了Canvas类,而目前在Android平台中,它主要任务为管理绘制过程,The
Canvasclass holds the &draw& calls. To draw something, you need 4 basiccomponents: A Bitmap to hold the pixels, a Canvas to host the draw calls(writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap),and a paint (to describe the colors
and styles for the drawing).
该类主要提供了三种构造方法,分别为构造一个空的Canvas、从Bitmap中构造和从GL对象中创建,如下
Canvas(Bitmap bitmap)
Canvas(GL gl)
&同时Canvas类的一些字段保存着重要的绘制方法定义,比如Canvas.HAS_ALPHA_LAYER_SAVE_FLAG保存时需要alpha层,对于Canvas类提供的方法很多,每个都很重要,下面我们一一作介绍
void&concat(Matrix matrix)
void&drawARGB(int a, int r, int g, int b)
void& drawArc(RectF oval, float startAngle, float sweepAngle, booleanuseCenter, Paint paint)
void&drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
void&drawBitmap(int[] colors, int offset, int stride, float x, float y, int width,int height, boolean hasAlpha, Paint paint)
void& drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
void& drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
void& drawBitmap(int[] colors, int offset, int stride, int x, int y, intwidth, int height, boolean hasAlpha, Paint paint)
void& drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
void& drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[]verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
void&drawCircle(float cx, float cy, float radius, Paint paint)
void&drawColor(int color)
void&drawColor(int color, PorterDuff.Mode mode)
android.graphics.Matrix
利用Bitmap和Matrix实现图像变换:剪切、旋转、缩放等操作。
用源Bitmap通过变换生成新的Bitmap的方法:
public static BitmapcreateBitmap(Bitmap source, int x, int y, intwidth, int height,&&
&&&&&&&&&&&
Matrix m, boolean filter)&&
public static BitmapcreateBitmap(Bitmap source, int x, int y, intwidth, int height)&&
public static BitmapcreateScaledBitmap(Bitmap src, int dstWidth,&&
&&&&&&&&&&&
int dstHeight,boolean filter)&
第一个方法是最终的实现,后两种只是对第一种方法的封装。
第二个方法可以从源Bitmap中指定区域(x,y,
width, height)中挖出一块来实现剪切;第三个方法可以把源Bitmap缩放为dstWidth
x dstHeight的Bitmap。
设置Matrix的Rotate(通过setRotate())或者Scale(通过setScale()),传入第一个方法,可实现旋转或缩放。
原文链接:/Linux/49p2.htm&
有关图形的变换、缩放等相关操作常用的方法有:
& void&reset() //
重置一个matrix对象。
& void&set(Matrix src) //复制一个源矩阵,和本类的构造方法Matrix(Matrix
src)& 一样
& boolean&isIdentity() //返回这个矩阵是否定义(已经有意义)
& voidsetRotate(float degrees) //指定一个角度以0,0为坐标进行旋转
& void&setRotate(float degrees, float px, float py)& //指定一个角度以px,py为坐标进行旋转
& void&setScale(float sx, float sy)& //
& void&setScale(float sx, float sy, float px, float py)& //以坐标px,py进行缩放
& voidsetTranslate(float dx, float dy) //平移
&void setSkew(float kx, float ky, float px, float py) //以坐标px,py进行倾斜
&void setSkew(float kx, float ky) //倾斜

我要回帖

更多关于 bitmap drawable 的文章

 

随机推荐