Bitmap的一些操作
来源:互联网 发布:sql验证身份证号码 编辑:程序博客网 时间:2024/06/07 04:53
* 旋转图片
*
* @param bmp
* @param degrees
* @return
*/
public Bitmap rotateIMG(Bitmap bmp, float degrees) {
Bitmap bitmap = null;
Matrix matrix = new Matrix();
matrix.setRotate(degrees);
bitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), matrix, true);
return bitmap;
}
/* 压缩到指定宽高 */
private Bitmap getBitmapFromFile(String pathName, int width, int height) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
Bitmap src = BitmapFactory.decodeFile(pathName, opts);
opts.outWidth = width;
opts.outHeight = height;
opts.inJustDecodeBounds = false;
src = BitmapFactory.decodeFile(pathName, opts);
Toast.makeText(this, src.getWidth() + " " + src.getHeight(),
Toast.LENGTH_SHORT).show();
int w = src.getWidth();
int h = src.getHeight();
float scaleWidth = ((float) width) / w;
float scaleHeight = ((float) height) / h;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bmp = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true);
Toast.makeText(this, bmp.getWidth() + " " + bmp.getHeight(),
Toast.LENGTH_SHORT).show();
return bmp;
}
/**
* 得到文件路径
*
* @return
*/
private File getFile() {
File file = new File("/sdcard/epd/sc.txt");
try {
boolean sdCardExist = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
if (sdCardExist) {
String fileName = "epd";
String sdPath = Environment.getExternalStorageDirectory()
.getPath();
File tempFile = new File(sdPath + File.separator + fileName);
if (!tempFile.exists()) {
tempFile.mkdirs();
}
file = new File(sdPath + File.separator + fileName
+ File.separator + "sc" + ".txt");
/*
* if (file.exists()) { file.delete(); file.createNewFile(); }
*/
}
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
/*文件保存*/
FileOutputStream fos = null;
try {
File file = getFile();
fos = new FileOutputStream(file, false);
fos.write(buffer);
fos.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (fos != null)
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* time:2015-07-06
* 读取文件
* @param path
* @return
*/
private byte[] getImageBytes() {
byte[] buffer = null;
File file = getFile();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
int lenght = fis.available();
buffer = new byte[lenght];
fis.read(buffer);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return buffer;
}
- Bitmap的一些操作
- Bitmap的一些操作
- Bitmap的一些操作
- Bitmap的一些操作
- Bitmap的一些操作
- android Bitmap的一些操作
- Bitmap的一些常用操作
- Bitmap的一些基本操作
- android bitmap的 一些简单操作
- android系列:Bitmap的一些操作
- bitmap和drawable的一些简单操作
- android bitmap的 一些简单操作
- Android开发-对bitmap的一些的操作
- BITMAP的一些知识
- bitmap的一些操作方法
- bitmap的一些工具
- 有关bitmap的操作
- Bitmap的操作
- Android 开源框架Universal-Image-Loader完全解析(三)---源代码解读
- linux命令行路径补全忽略大小写
- 基于quartz1.66+spring2.5的一个模块化设计
- DirectX怪像之一,我的模型不见了
- 求100到200间的全部素数
- Bitmap的一些操作
- PL/SQL和SQLPLUS查询结果不一样——千万别忘记commit!
- 哈佛图书馆的二十条训言
- windows 设置环境变量 账户管理win7中设置
- 复杂度与时间效率的关系
- PL/SQL Developer无法登录Oracle
- 可穿戴设备(CC2541)上微信(2)
- tmux复制模式
- Java NIO:浅析I/O模型