我试图在 imageView 中旋转图像,并使用相同的图像旋转位图。
(我需要那个位图,因为我稍后将图像发送到服务器)
编码:
image.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
mPhoto=rotate(mPhoto,90);
image.setImageBitmap(mPhoto);
}
});
旋转()方法:
public static Bitmap rotate(Bitmap src, float degree) {
// create new matrix
Matrix matrix = new Matrix();
// setup rotation degree
matrix.postRotate(degree);
// return new bitmap rotated using matrix
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}
日志猫:
08-29 23:14:34.964: W/dalvikvm(20087): threadid=1: thread exiting with uncaught exception (group=0x41505930)
08-29 23:14:34.968: E/AndroidRuntime(20087): FATAL EXCEPTION: main
08-29 23:14:34.968: E/AndroidRuntime(20087): java.lang.OutOfMemoryError
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.graphics.Bitmap.nativeCreate(Native Method)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.graphics.Bitmap.createBitmap(Bitmap.java:689)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.graphics.Bitmap.createBitmap(Bitmap.java:666)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.graphics.Bitmap.createBitmap(Bitmap.java:599)
08-29 23:14:34.968: E/AndroidRuntime(20087): at com.example.free.Add.rotate(Add.java:356)
08-29 23:14:34.968: E/AndroidRuntime(20087): at com.example.free.Add$5.onClick(Add.java:137)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.view.View.performClick(View.java:4211)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.view.View$PerformClick.run(View.java:17362)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.os.Handler.handleCallback(Handler.java:725)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.os.Handler.dispatchMessage(Handler.java:92)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.os.Looper.loop(Looper.java:137)
08-29 23:14:34.968: E/AndroidRuntime(20087): at android.app.ActivityThread.main(ActivityThread.java:5227)
08-29 23:14:34.968: E/AndroidRuntime(20087): at java.lang.reflect.Method.invokeNative(Native Method)
08-29 23:14:34.968: E/AndroidRuntime(20087): at java.lang.reflect.Method.invoke(Method.java:511)
08-29 23:14:34.968: E/AndroidRuntime(20087): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-29 23:14:34.968: E/AndroidRuntime(20087): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-29 23:14:34.968: E/AndroidRuntime(20087): at dalvik.system.NativeStart.main(Native Method)
希望你能帮助我。
泰!