通过不同形式获取Bitmap,以及创建Bitmap
来源:互联网 发布:java做自动化测试 编辑:程序博客网 时间:2024/06/13 11:27
package com.hqzn.view;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.util.TypedValue;
import java.io.InputStream;
/**位图获取
* Created by Administrator on 2016/9/27.
*/
public class BitmapUtils {
/**
* 通过不同种形式获取资源文件
* @param res
* @param resId
* @return
*/
//通过资源ID
public static Bitmap getBitmapFromResource(Resources res, int resId) {
return BitmapFactory.decodeResource(res, resId);
}
public static Bitmap getBitmapFromResourceOptions(Resources res, int resId, BitmapFactory.Options options){
return BitmapFactory.decodeResource(res, resId,options);
}
public static Bitmap getBitmapFromResourceOptionsIO(Resources res, int resId, BitmapFactory.Options options, InputStream is, Rect rect, TypedValue typedValue){
return BitmapFactory.decodeResourceStream(res,typedValue,is,rect,options);
}
//文件
public static Bitmap getBitmapFromFile(String pathName) {
return BitmapFactory.decodeFile(pathName);
}
public static Bitmap getBitmapFromFileOptions(String pathName, BitmapFactory.Options options){
return BitmapFactory.decodeFile(pathName,options);
}
//字节数组
public static Bitmap getBytes2Bimap(byte[] b) {
if (b.length != 0) {
return BitmapFactory.decodeByteArray(b, 0, b.length);
} else {
return null;
}
}
public static Bitmap getBytes2BimapOptions(byte[] b, BitmapFactory.Options options) {
if (b.length != 0) {
return BitmapFactory.decodeByteArray(b, 0, b.length,options);
} else {
return null;
}
}
//输入流
public static Bitmap getBitmapFromStream(InputStream inputStream) {
return BitmapFactory.decodeStream(inputStream);
}
public static Bitmap getBitmapFromStreamOptions(InputStream inputStream, Rect rect, BitmapFactory.Options options){
return BitmapFactory.decodeStream(inputStream,rect,options);
}
public static Bitmap getBitmapFromStreamOptionsInternal(InputStream inputStream, Rect rect, BitmapFactory.Options options){
return BitmapFactory.decodeStream(inputStream,rect,options);
}
/**
* 创建位图
* @param src
* @return
*/
//以src为原图生成不可变得新图像
public static Bitmap createBitmap(Bitmap src){
return Bitmap.createBitmap(src);
}
//以src为原图,创建新的图像,指定新图像的高宽以及是否变。
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,int dstHeight, boolean filter){
return Bitmap.createScaledBitmap(src,dstWidth,dstHeight,filter);
}
//创建指定格式、大小的位图
public static Bitmap createBitmap(int width, int height, Bitmap.Config config){
return Bitmap.createBitmap(width,height,config);
}
//以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height){
return Bitmap.createBitmap(source,x,y,width,height);
}
// //
// public static public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
}
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.util.TypedValue;
import java.io.InputStream;
/**位图获取
* Created by Administrator on 2016/9/27.
*/
public class BitmapUtils {
/**
* 通过不同种形式获取资源文件
* @param res
* @param resId
* @return
*/
//通过资源ID
public static Bitmap getBitmapFromResource(Resources res, int resId) {
return BitmapFactory.decodeResource(res, resId);
}
public static Bitmap getBitmapFromResourceOptions(Resources res, int resId, BitmapFactory.Options options){
return BitmapFactory.decodeResource(res, resId,options);
}
public static Bitmap getBitmapFromResourceOptionsIO(Resources res, int resId, BitmapFactory.Options options, InputStream is, Rect rect, TypedValue typedValue){
return BitmapFactory.decodeResourceStream(res,typedValue,is,rect,options);
}
//文件
public static Bitmap getBitmapFromFile(String pathName) {
return BitmapFactory.decodeFile(pathName);
}
public static Bitmap getBitmapFromFileOptions(String pathName, BitmapFactory.Options options){
return BitmapFactory.decodeFile(pathName,options);
}
//字节数组
public static Bitmap getBytes2Bimap(byte[] b) {
if (b.length != 0) {
return BitmapFactory.decodeByteArray(b, 0, b.length);
} else {
return null;
}
}
public static Bitmap getBytes2BimapOptions(byte[] b, BitmapFactory.Options options) {
if (b.length != 0) {
return BitmapFactory.decodeByteArray(b, 0, b.length,options);
} else {
return null;
}
}
//输入流
public static Bitmap getBitmapFromStream(InputStream inputStream) {
return BitmapFactory.decodeStream(inputStream);
}
public static Bitmap getBitmapFromStreamOptions(InputStream inputStream, Rect rect, BitmapFactory.Options options){
return BitmapFactory.decodeStream(inputStream,rect,options);
}
public static Bitmap getBitmapFromStreamOptionsInternal(InputStream inputStream, Rect rect, BitmapFactory.Options options){
return BitmapFactory.decodeStream(inputStream,rect,options);
}
/**
* 创建位图
* @param src
* @return
*/
//以src为原图生成不可变得新图像
public static Bitmap createBitmap(Bitmap src){
return Bitmap.createBitmap(src);
}
//以src为原图,创建新的图像,指定新图像的高宽以及是否变。
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,int dstHeight, boolean filter){
return Bitmap.createScaledBitmap(src,dstWidth,dstHeight,filter);
}
//创建指定格式、大小的位图
public static Bitmap createBitmap(int width, int height, Bitmap.Config config){
return Bitmap.createBitmap(width,height,config);
}
//以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height){
return Bitmap.createBitmap(source,x,y,width,height);
}
// //
// public static public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
}
0 0
- 通过不同形式获取Bitmap,以及创建Bitmap
- android--创建不同的bitmap
- android 创建不同的bitmap
- bitmap的不同获取方式
- 通过一个View创建Bitmap
- android 通过流获取bitmap
- Android 通过URI获取Bitmap
- Android 不同版本下Bitmap创建差异
- 使用Bitmap.createBitmap 创建和BitmapFactory.decode....获取Bitmap对象
- 创建BitMap
- 通过BYTE数组创建Gdiplus::Bitmap
- Android 通过Uri获取Bitmap对象
- Android通过url获取bitmap图片问题
- Android中通过BitmapDrawable获取Bitmap
- 通过路径获取本地图片bitmap
- Android 通过Uri获取Bitmap对象
- Android中通过url获取图片Bitmap
- 通过MP3获取专辑背景图片(Bitmap)
- Xcode快捷键
- Java语法----Java中equals和==的区别(转载)
- linux中vi命令
- Ubuntu Make新版上线:支持安装Swift编程语言
- C语言中char*和char[]用法区别分析&微软编译器的坑
- 通过不同形式获取Bitmap,以及创建Bitmap
- 【数据结构与算法】二叉树递归与非递归遍历
- Scala集合操作
- android自定义popupWindow
- java客户端动态调用webservice服务
- 怎么理解state thread库?
- 机器学习算法笔记
- IP头、TCP头、UDP头详解以及定义
- dropdownlist控件取值用法介绍