-
图片压缩
-
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
-
-
- Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/dcim/Camera/hello.jpg",options);
- options.inJustDecodeBounds =false;
-
- int be = (int)(options.outHeight / (float)200);
- if(be <= 0)
- be =1;
- options.inSampleSize =be;
-
- bitmap = BitmapFactory.decodeFile("/sdcard/dcim/Camera/hello.jpg",options);
- int w = bitmap.getWidth();
- int h=bitmap.getHeight();
- System.out.println(w+" "+h);
- myImageView.setImageBitmap(bitmap);
-
-
-
- File file2= new File("/sdcard/dcim/Camera/test.jpg");
- try {
- FileOutputStream out = new FileOutputStream(file2);
- if(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)){
- out.flush();
- out.close();
- }
- } catch (Exception e) {
-
- }
-
-
-
- File file =new File("/sdcard/dcim/Camera/test.jpg");
- int maxBufferSize = 16 * 1024;
-
- int len = 0;
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- BufferedInputStream bufferedInputStream;
- try {
- bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
- int bytesAvailable = bufferedInputStream.available();
- int bufferSize = Math.min(bytesAvailable, maxBufferSize);
- byte[] buffer = new byte[bufferSize];
- while ((len = bufferedInputStream.read(buffer)) != -1)
- {
- outStream.write(buffer, 0, bufferSize);
- }
- data = outStream.toByteArray();
- outStream.close();
- bufferedInputStream.close();
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
相关阅读:
GridView加ObjectDataSource做删除事件(ObjectDataSourceStatusEventHandler 委托)
非常酷的三级下拉菜单!!(javascript)
sql事务处理(转)
首页头部下拉广告设计(javascript)
JavaScript 强行弹出窗口 与 无提示关闭页面
androd之绘制文本(FontMetrics)[转]
Android 字 成 圆
python写的二分插入算法
Loading效果 UIActivityIndicatorView
ios6.0 调用系统api 分享到 twitter facebook weibo
-
原文地址:https://www.cnblogs.com/qchy/p/2981682.html
Copyright © 2020-2023
润新知