Android——Bitmap及其BitmapFactory的常用方法
来源:互联网 发布:ios8录屏软件 编辑:程序博客网 时间:2024/06/01 12:18
1.BitMap类
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight,
boolean filter)——以src为原图,创建新的图像,指定新图像的高宽以及是否可变。
int pieceWidth = (int) (lineHeight * radioOflineHeight);
例如:whitePiece 是一张BitMap图片
whitePiece = Bitmap.createScaledBitmap(whitePiece, pieceWidth, pieceWidth,
false);
public final int getWidth()——获取位图的宽度
public final int getHeight()——获取位图的高度
public boolean compress(CompressFormat format, int quality, OutputStream
stream)——按指定的图片格式以及画质,将图片转换为输出流。
format:Bitmap.CompressFormat.PNG或者Bitmap.CompressFormat.JPEG
quality:画质,0-100.0表示最低画质压缩,100以最高画质压缩。对于PNG等无损格
式的图片,会忽略此项设置。
常用的静态方法:
public static Bitmap createBitmap(Bitmap src) ——以src为原图生成不可变得新图像
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,
int dstHeight, boolean filter)——以src为原图,创建新的图像,指定新图像的高宽以
及是否可变。
public static Bitmap createBitmap(int width, int height, Config config)——创建指
定格式、大小的位图
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int
height)以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。
2.BitmapFactory工厂类:
public int inSampleSize——图片缩放的倍数。如果设为4,则宽和高都为原来的1/4,
则图是原来的1/16。
public int outWidth——获取图片的宽度值
public int outHeight——获取图片的高度值
//第一种方式:从资源文件中得到图片
public static Bitmap decodeResource(Resources res, int id)
//第二种方式:从SD卡中得到图片
String SDCarePath=Environment.getExternalStorageDirectory().toString();
String filePath=SDCarePath+”/”+”haha.jpg”;
Bitmap rawBitmap1 = BitmapFactory.decodeFile(filePath, null);
从输入流中解码位图
public static Bitmap decodeStream(InputStream is)
public BitmapDrawable(Resources res, Bitmap bitmap)——在资源中从bitmap变
BitMapdrawable
通过BitmapDrawable显示位图
1 // 获取位图
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic180);
2 // 转换为BitmapDrawable对象
BitmapDrawable bmpDraw=new BitmapDrawable(bmp);
3 // 显示位图
ImageView iv2 = (ImageView)findViewById(R.id.ImageView02);
iv2.setImageDrawable(bmpDraw);
将Bitmap保存到SDCard中,方便于原图片的比较
this.compressAndSaveBitmapToSDCard(newBitmap, “xx100.jpg”, 80);
根据资源res转换成BitMap大图:
// 获得大图
1.Bitmap bitmap = ((BitmapDrawable)
getResources().getDrawable(R.drawable.xxx)).getBitmap();
2.Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.xxx);
将大图分割成小图:
for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { //bitmap是大图 Bitmap bm = Bitmap.createBitmap(bitmap, j * mWidthAndHeight, i * mWidthAndHeight, mWidthAndHeight, mWidthAndHeight); ivs[i][j] = new ImageView(act); ivs[i][j].setImageBitmap(bm); }}
更详细方法http://www.cnblogs.com/Free-Thinker/p/6394818.html
- Android——Bitmap及其BitmapFactory的常用方法
- Android中一些常用类的常用方法(Math、Random、Color、Paint、Canvas、Bitmap、BitmapFactory)
- Android 4K高清图片解码显示(2)BitmapFactory常用Bitmap的解码方法
- Android入门——Bitmap和BitmapFactory
- android BitmapFactory的OutOfMemoryError: bitmap ...
- Bitmap——BitmapFactory.Options的使用
- Bitmap——BitmapFactory.Options
- Bitmap—— BitmapFactory.decodeFile
- Android学习之——图形图像处理(Bitmap、BitmapFactory)(一)
- Android学习之——图形图像处理(Bitmap、BitmapFactory)(一)
- Android 从源码分析Bitmap和BitmapFactory常用API
- 使用BitmapFactory不同方法解析Bitmap的简单分析
- Android图片之Bitmap、BitmapFactory
- android的Bitmap和BitmapFactory类的使用
- Android Bitmap类的常用方法
- Android的Bitmap类中常用方法
- Android中常用的bitmap处理方法
- BitmapFactory中常用的几个静态方法
- 嵌入式硬件--串口->LCD
- ThinkPHP3.2 --- URL去除index.php方法
- spring的IOC全程解析
- HDU 4185 Oil Skimming (最大匹配)
- Web局部刷新的实现
- Android——Bitmap及其BitmapFactory的常用方法
- Intent传输数据-3
- 3D Systems Geomagic Design X 2016.1.0 x64\
- hdu 2369
- notepad++运行python/C/C++/perl32
- Python练习17-----pytz 模块的安装
- Bentley MicroStation CONNECT Edition Update 3 10.03.00.30 Full Win64 1DVD
- 转:PC上 python 通过串口和 arduino 读写交互成功,哈哈,真好玩
- 算法概论第八章练习题 8.19