android 将图片内容解析成字节数组,将字节数组转换为Ima ...
来源:互联网 发布:中华大字典软件 编辑:程序博客网 时间:2024/05/21 12:48
http://www.eoeandroid.com/thread-91650-1-1.html
- 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;
- }
-
- }
0 2
- android 将图片内容解析成字节数组,将字节数组转换为Ima ...
- 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 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Java将字节数组转换成字符串
- 如何将BufferedImage转换成字节数组?
- 用VB.NET将字节数组转换为字符串
- 用VB.NET将字节数组转换为字符串
- 用VB.NET将字节数组转换为字符串
- 如何将字节数组转换为十六进制的字符串
- 将图片转化为字节数组更好的方法
- 图片获取字节数组byte[]data, 将字节数组转换为String,之后再由String转换为byte[]data,会发现不同
- 将Inputstream转化为字节数组
- 将一个字节数组从任意字节offset开始,长为len的字节转换为整数
- open gl 相关网址
- C/C++日常学习总结(第六篇)多基派生引起的虚函数访问二义性问题&重载,覆盖,隐藏的区别
- 将特殊格式的NSSring转换成NSDate
- Device Tree常用方法解析
- 在Android中自定义捕获Application全局异常,可以替换掉系统的强制退出对话框
- android 将图片内容解析成字节数组,将字节数组转换为Ima ...
- Levinux,解决在非linux系统下在linux环境中使用和学习python问题
- Emacs (坑)
- 3DS电游“妖怪手表”销量破百万 7月出售新作
- VC++ 获取文件属性创建时间、修改时间和访问时间
- Java包命名规则引发的思考Java包命名规则引发的思考
- iOS kvo 结合 FBKVOController 的使用
- 微信+上品折扣:微信商场O2O第一战打阿里大本营
- 解析oracle的rownum(转)