簡體   English   中英

getDrawingCache()始終返回null

[英]getDrawingCache() always returns null

我知道這個問題經常被問到,但這似乎有所不同。 我已經嘗試了StackOverflow的6種解決方案,但沒有成功。 當他們離開應用程序時,我嘗試將某人制作的繪圖放入Notification.BigPictureStyle

    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        _thread.setRunning(true);
        _thread.start();            
        setDrawingCacheEnabled(true);
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        _thread.setRunning(false);

        measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        layout(0, 0, getMeasuredWidth(), getMeasuredHeight());

        buildDrawingCache(false);
        Bitmap currentState = Bitmap.createBitmap(getDrawingCache());
        setDrawingCacheEnabled(false);

        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notificationIntent = new Intent(DrawActivity.this, DrawActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(DrawActivity.this, 0, notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        Notification noti = new Notification.BigPictureStyle(
                new Notification.Builder(DrawActivity.this)
                    .setContentTitle("Your drawing")
                    .setContentText("Unfold to see drawing")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(contentIntent))
        .setSummaryText("Here you can see how you left your drawing.")
        .bigPicture(currentState)
        .build();

        manager.notify(1023, noti);

    }
}

但是我總是在這行得到一個NullPointerException

Bitmap currentState = Bitmap.createBitmap(getDrawingCache());

此代碼來自StackOverflow,其中啟用了所有這些緩存。 有人知道出什么事了嗎?

順便說一句,我當然使用的是Android 4.1.1。

類似的問題在這里更多信息在這里 ...

問題似乎是您無法訪問Surfaceview的內容-顯然您可以捕獲ImageView的內容...我認為您使用的是surfaceView,因此遇到了同樣的問題...如果您願意進一步挖掘, 可能幫助(來自上述主題之一)

如果您不使用Surfaceview,則setLayerType可能是您的答案...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM