将图像旋转90度

时间:2015-07-07 11:29:44

标签: android image rotation 360-degrees

是否可以旋转图像 90度

注意:旋转不在ImageView对象中,而是在路径中的原始图像中 非常感谢

      public void Rotate90 (){ 

//      Rotate90 this       File image1= new File(Environment.getExternalStorageDirectory().getPath() + "/0Students/Compressed_Images/t12.jpg" );
    }

4 个答案:

答案 0 :(得分:2)

首先从文件中加载图片

Bitmap bitmap = BitmapFactory.decodeFile(image Path);

然后制作一个矩阵

Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap finalBitmap = Bitmap.createBitmap(bitmap , 0, 0,
                bitmap .getWidth(), bitmap .getHeight(),
                matrix, true);

then save it to your system 



   private void SaveImage(Bitmap finalBitmap) {

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/saved_images");    
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-"+ n +".jpg";
    File file = new File (myDir, fname);
    if (file.exists ()) file.delete (); 
    try {
           FileOutputStream out = new FileOutputStream(file);
           finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
           out.flush();
           out.close();

    } catch (Exception e) {
           e.printStackTrace();
    }
}

并且不要忘记添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

希望这能帮到你:)

答案 1 :(得分:1)

/**
 * Populate the {@link MessageChannel} to the new {@link IntegrationFlowBuilder}
 * chain, which becomes as a {@code requestChannel} for the Messaging Gateway(s) built
 * on the provided service interface.
 * <p>A gateway proxy bean for provided service interface is registered under a name
 * from the
 * {@link org.springframework.integration.annotation.MessagingGateway#name()} if present
 * or from the {@link IntegrationFlow} bean name plus {@code .gateway} suffix.
 * @param serviceInterface the service interface class with an optional
 * {@link org.springframework.integration.annotation.MessagingGateway} annotation.
 * @return new {@link IntegrationFlowBuilder}.
 */
public static IntegrationFlowBuilder from(Class<?> serviceInterface) {

答案 2 :(得分:0)

答案 3 :(得分:0)

1)您必须从您的路径获取位图,如下所示:

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}

2)将myBitmap传递给此函数以获得旋转90度的图像

public static Bitmap RotateBitmap(Bitmap source, float angle) {
  Matrix matrix = new Matrix();
  matrix.postRotate(angle);
  return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}