我開發的塗料應用程序,我想插入剪切功能,我用從CanvasView此代碼:如何裁剪位圖?
public void Crop() {
// TODO Auto-generated method stub
int value = 0;
if (bitmap.getHeight() <= bitmap.getWidth()) {
value = bitmap.getHeight();
} else {
value = bitmap.getWidth();
}
Bitmap finalBitmap = null;
finalBitmap = Bitmap.createBitmap(bitmap, 0, 0, value, value);
Bitmap lastBitmap = null;
lastBitmap = Bitmap.createScaledBitmap(finalBitmap, 144, 144, true);
}
但我recive以下錯誤
03-28 03:10:18.365: E/AndroidRuntime(19708): FATAL EXCEPTION: main
03-28 03:10:18.365: E/AndroidRuntime(19708): java.lang.NullPointerException
03-28 03:10:18.365: E/AndroidRuntime(19708): at baked.soft.CanvasView.Crop(CanvasView.java:670)
03-28 03:10:18.365: E/AndroidRuntime(19708): at baked.soft.FirstActivity$7.onClick(FirstActivity.java:157)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.view.View.performClick(View.java:4232)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.view.View$PerformClick.run(View.java:17318)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.os.Handler.handleCallback(Handler.java:615)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.os.Looper.loop(Looper.java:137)
03-28 03:10:18.365: E/AndroidRuntime(19708): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-28 03:10:18.365: E/AndroidRuntime(19708): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 03:10:18.365: E/AndroidRuntime(19708): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 03:10:18.365: E/AndroidRuntime(19708): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-28 03:10:18.365: E/AndroidRuntime(19708): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-28 03:10:18.365: E/AndroidRuntime(19708): at dalvik.system.NativeStart.main(Native Method)
這是錯誤行:
從FirstActivityif (bitmap.getHeight() <= bitmap.getWidth()) {
位圖
你在哪裏聲明位變量: -/ – 2013-03-28 01:17:36