如何捕获当前屏幕的屏幕截图以在 android libgdx 游戏中像 temple 运行 游戏一样分享分数只给出黑屏

How to CaptureScreen shot of current screen to share score like temple run game in android libgdx game gives only black screen

我想 post 我的游戏在社交应用上的屏幕截图。我使用 Libgdx 框架开发了这款游戏。我在 Core class 中创建了一个接口。这是它的 Intent 分享具体代码。

public interface ActionResolver {
   public void shareit();

   }

然后在我的 Android 启动器 class 上实现它

public class AndroidLauncher extends AndroidApplication implements
        ActionResolver{ .......

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

gameView = initializeForView(new MainGame(this),
                new AndroidApplicationConfiguration());// View
}

 @Override public void shareScreen() {

      String message = "Text I want to share."; Intent share = new
     Intent(Intent.ACTION_SEND); share.setType("text/plain");
      share.putExtra(Intent.EXTRA_TEXT, message);

      startActivity(Intent.createChooser(share,
      "Title of the dialog the system will open"));

      }


     public void createIntent(View v){

      { // View view =gameView.getRootView(); Bitmap icon =
      getBitmapFromView(v.getRootView()); Intent share = new
      Intent(Intent.ACTION_SEND); share.setType("image/jpeg");

      ContentValues values = new ContentValues();
      values.put(MediaStore.Images.Media.TITLE, "title");
      values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri =
      getContentResolver().insert(
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

      OutputStream outstream;

      try { outstream = getContentResolver().openOutputStream(uri);
      icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
      outstream.close(); } catch (Exception e) {
      System.err.println(e.toString()); }

      share.putExtra(Intent.EXTRA_STREAM, uri);
      startActivity(Intent.createChooser(share, "Share Image")); } }

public void createIntent(View v){

      Bitmap icon = getBitmapFromView(v.getRootView()); Intent share = new
      Intent(Intent.ACTION_SEND); share.setType("image/jpeg");

      ContentValues values = new ContentValues();
      values.put(MediaStore.Images.Media.TITLE, "title");
      values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri =
      getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
      values);


}
public static Bitmap getBitmapFromView(View view) {

        Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),
                view.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(returnedBitmap);
        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null)
            bgDrawable.draw(canvas);
        else
            canvas.drawColor(Color.WHITE);
        view.draw(canvas);
        return returnedBitmap;
    }

我还在 MainGame 中初始化了我的界面 class

public MainGame(ActionResolver actionResolver) {
        super();
        this.actionResolver = actionResolver;

有一件事我很困惑我应该通过哪个视图来启动这个意图?因为它的 libgdx 框架。其次在 Android 方面显然 Canvas,所有位图都来自 Android.

有了这整个代码,我就可以开始我的意图了,但是当我共享屏幕时,屏幕只是黑屏。但是该屏幕底部显示了一个广告,我已经通过 admob 使用了该广告。

我在这里搜索了很多,找到了分享黑屏的相关线程而不是游戏的实际屏幕截图。但我不明白这一切,因为有些人要求使用一些不同的图书馆。我不想为 facebook 使用任何外部库或 facebook sdk。我只想要简单的 android Intent 共享 Screen 。请帮助我。

com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap 适合我。

https://github.com/libgdx/libgdx/wiki/Take-a-Screenshot