android 照片旋转并保存
    /**     * 读取图片属性:旋转的角度     * @param path 图片绝对路径     * @return degree旋转的角度     */    public int readPictureDegree(String path) {        int degree  = 0;        try {                ExifInterface exifInterface = new ExifInterface(path);                int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);                switch (orientation) {                case ExifInterface.ORIENTATION_ROTATE_90:                        degree = 90;                        break;                case ExifInterface.ORIENTATION_ROTATE_180:                        degree = 180;                        break;                case ExifInterface.ORIENTATION_ROTATE_270:                        degree = 270;                        break;                }        } catch (IOException e) {                e.printStackTrace();        }        return degree;    } /*    * 旋转图片     * @param angle     * @param bitmap     * @return Bitmap     */    public Bitmap rotaingImageView(int angle , Bitmap bitmap) {         //旋转图片 动作          Matrix matrix = new Matrix();       matrix.postRotate(angle);       // 创建新的图片          return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);     }/***     * 将bitmap保存在SD jpeg格式     *      * @param bitmap     *            图片bitmap     * @param filePath     *            要保存图片路径     * @param quality     *            压缩质量值     */    public void saveImage(Bitmap bitmap, String filePath, int quality) {        FileOutputStream fileOutputStream = null;        try {            fileOutputStream = new FileOutputStream(filePath);            bitmap.compress(CompressFormat.JPEG, quality, fileOutputStream);            fileOutputStream.flush();            fileOutputStream.close();            // 如果图片还没有回收,强制回收            if (!bitmap.isRecycled()) {                bitmap.recycle();                System.gc();            }        } catch (Exception e) {        }    }bitmap=ImageCompress.decodeSampledBitmapFromResource(filename, 480, 800);                                        //图片旋转                    int Degree = imageUtils.readPictureDegree(filename);                    bitmap = imageUtils.rotaingImageView(Degree, bitmap);                    //保存图片到SD卡                    //imageCompress.saveImage(bitmap, filename);                    imageCompress.saveImage(bitmap, filename,90);
View Code

android 照片旋转并保存
/***     * 动态设置inSampleSize 倍数     *      * @param pathName     *            图片路径     * @param reqWidth     *            要压缩的宽度     * @param reqHeight     *            要压缩的高度     * @return     */    public static Bitmap decodeSampledBitmapFromResource(String pathName,            int reqWidth, int reqHeight) {        // 首先设置 inJustDecodeBounds=true 来获取图片尺寸        final BitmapFactory.Options options = new BitmapFactory.Options();        options.inJustDecodeBounds = true;        BitmapFactory.decodeFile(pathName, options);        // 计算 inSampleSize 的值        options.inSampleSize = calculateInSampleSize(options, reqWidth,                reqHeight);        // 根据计算出的 inSampleSize 来解码图片生成Bitmap        options.inJustDecodeBounds = false;        return BitmapFactory.decodeFile(pathName, options);    }
View Code

更多相关文章

  1. android等比例缩放图片
  2. android 笔记 --- Android-图片透明度处理代码
  3. Android Retrofit2.0 上传单张图片和多张图片
  4. android bitmap图片压缩,打时间水印。
  5. 在Android中调用图片、视频、音频、录音、拍照
  6. Android通过网络URL获取图片并显示
  7. ClipDrawable制作图片渐进效果
  8. Android拍照后图片旋转问题

随机推荐

  1. android.hardware.Camera翻译
  2. Android已有项目接入Flutter及互相通信
  3. 36个Android开发常用经典代码大全
  4. Android非主线程更新UI
  5. Android(安卓)获取地理位置的经度和纬度(
  6. Unity 调用 Android(安卓)Native 方法(一
  7. android 建议在onPause和onStop处理的事
  8. 在Windows下搭建Android开发环境
  9. Android(安卓)高通代码预制apk可卸载,恢复
  10. Android(安卓)timer