2012-11-01 201 views
1

我已經寫了代碼來繪製圖像上的文本其工作正常我捕獲圖像在potrait模式,但應用程序崩潰時,我在橫向模式捕獲圖像,我收到異常Java.lang .IllegalStateException:傳遞給帆布構造在畫布上畫圖片

Canvas canvas = new Canvas(photo); 
        Typeface tf = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); 
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 
        paint.setStyle(Style.FILL); 
        paint.setTypeface(tf); 
        paint.setColor(Color.WHITE); 
        paint.setStrokeWidth(12); 
        canvas.drawBitmap(photo, 0, 0, paint); 
        canvas.drawText(topaste, 10, 115, paint); 
        image.setImageBitmap(photo); 

回答

1

不可變位基本上畫布對象需要一個新的位圖繪製到,在你不可改變的圖像通過擊敗後繪製操作的點。以下代碼爲畫布創建一個新的位圖。您將需要替換寬度和高度變量以匹配您的用例:

Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) 
Canvas canvas = new Canvas(photo); 
+0

任何解釋爲什麼這隻發生在風景雖然嗎? – aaronmarino