android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
来源:互联网 发布:淘宝评价截图 编辑:程序博客网 时间:2024/05/21 03:26
http://blog.csdn.net/z104207/article/details/6634774
- package com.bingo.util;
- import java.io.BufferedOutputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Matrix;
- public class ImageDispose {
- /**
- * @param 将图片内容解析成字节数组
- * @param inStream
- * @return byte[]
- * @throws Exception
- */
- public static byte[] readStream(InputStream inStream) throws Exception {
- byte[] buffer = new byte[1024];
- int len = -1;
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- while ((len = inStream.read(buffer)) != -1) {
- outStream.write(buffer, 0, len);
- }
- byte[] data = outStream.toByteArray();
- outStream.close();
- inStream.close();
- return data;
- }
- /**
- * @param 将字节数组转换为ImageView可调用的Bitmap对象
- * @param bytes
- * @param opts
- * @return Bitmap
- */
- public static Bitmap getPicFromBytes(byte[] bytes,
- BitmapFactory.Options opts) {
- if (bytes != null)
- if (opts != null)
- return BitmapFactory.decodeByteArray(bytes, 0, bytes.length,
- opts);
- else
- return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
- return null;
- }
- /**
- * @param 图片缩放
- * @param bitmap 对象
- * @param w 要缩放的宽度
- * @param h 要缩放的高度
- * @return newBmp 新 Bitmap对象
- */
- public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h){
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- Matrix matrix = new Matrix();
- float scaleWidth = ((float) w / width);
- float scaleHeight = ((float) h / height);
- matrix.postScale(scaleWidth, scaleHeight);
- Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
- matrix, true);
- return newBmp;
- }
- /**
- * 把Bitmap转Byte
- * @Author HEH
- * @EditTime 2010-07-19 上午11:45:56
- */
- public static byte[] Bitmap2Bytes(Bitmap bm){
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
- return baos.toByteArray();
- }
- /**
- * 把字节数组保存为一个文件
- * @Author HEH
- * @EditTime 2010-07-19 上午11:45:56
- */
- public static File getFileFromBytes(byte[] b, String outputFile) {
- BufferedOutputStream stream = null;
- File file = null;
- try {
- file = new File(outputFile);
- FileOutputStream fstream = new FileOutputStream(file);
- stream = new BufferedOutputStream(fstream);
- stream.write(b);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- return file;
- }
- }
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byt
- android 将图片内容解析成字节数组,将字节数组转换为Ima ...
- 服务器返回的图片格式是 图片字节数组,把字节数组转换成data然后用imageView展示出来
- 图片获取字节数组byte[]data, 将字节数组转换为String,之后再由String转换为byte[]data,会发现不同
- 将图片转化为字节数组更好的方法
- 如何将YUV的byte数组转换为bitmap
- Android 调用照相机拍照把照片转化为字节数组
- Bitmap转灰度字节数组byte[]
- 将一个字节数组从任意字节offset开始,长为len的字节转换为整数
- 将传入的对象转换成一个字节数组
- 将bitmap对象保存为一个图片文件
- 图片文件和byte字节数组的转换
- c++动态联编与静态联编
- Storyboard全解析-第一部分
- QT编程----事件
- php截取字符串比较有用的。中英文都可以
- 【IOS】cocos2d-x 内存释放问题的解决过程
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android序列化与反序列话HashMap到sqlite数据库
- C++字符换行
- 批处理加密
- jvm的内部体系结构浅析
- CDocument::SetModifiedFlag
- 关于android Http访问,上传,用了三个方法
- MFC单文档(SDI)转换成多文档(MDI)解决方案
- dbcc Trace