Android截屏表面視圖顯示黑屏我試圖通過代碼拍攝我的游戲的截圖,并通過一個意圖來分享它。我能做這些事情,但是截圖總是看起來是黑色的。下面是與分享截圖相關(guān)的代碼:View view = MainActivity.getView();view.setDrawingCacheEnabled(true);Bitmap screen = Bitmap.createBitmap(view.getDrawingCache(true));.. save Bitmap這是MainActivity中的內(nèi)容:view = new GameView(this);view.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));public static SurfaceView getView() {
return view;}以及視圖本身:public class GameView extends SurfaceView implements SurfaceHolder.Callback {private static SurfaceHolder surfaceHolder;...etc我就是這樣畫所有東西的:Canvas canvas = surfaceHolder.lockCanvas(null);
if (canvas != null) {
Game.draw(canvas);...好的,基于一些答案,我構(gòu)建了:public static void share() {
Bitmap screen = GameView.SavePixels(0, 0, Screen.width, Screen.height);
Calendar c = Calendar.getInstance();
Date d = c.getTime();
String path = Images.Media.insertImage(
Game.context.getContentResolver(), screen, "screenShotBJ" + d + ".png", null);
System.out.println(path + " PATH");
Uri screenshotUri = Uri.parse(path);
final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");
Game.context.startActivity(Intent.createChooser(emailIntent,
"Share High Score:"));}鏡頭仍然是黑色的。我拯救它的方式有什么問題嗎?我嘗試過幾種不同的方法來獲取屏幕快照,但是沒有一種方法起作用:上面代碼中顯示的方法是最常用的方法。但這似乎行不通。這是使用SurfaceView的問題嗎?如果是這樣的話,如果我不能使用它,為什么view.getDrawinCache(True)還存在,以及如何解決這個問題?謝謝。
- 3 回答
- 0 關(guān)注
- 2366 瀏覽
添加回答
舉報
0/150
提交
取消