【问题标题】:How to CaptureScreen shot of current screen to share score like temple run game in android libgdx game gives only black screen如何捕获当前屏幕的屏幕截图以在 android libgdx 游戏中像寺庙运行游戏一样分享分数只给出黑屏
【发布时间】:2015-04-24 07:52:31
【问题描述】:

我想在社交应用上发布我的游戏屏幕截图。我使用 Libgdx 框架开发了这个游戏。我在 Core 类中创建了一个接口。这是它的 Intent 共享特定代码。

public interface ActionResolver {
   public void shareit();

   }

然后在我的 Androidlauncher 类上实现它

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 类中初始化我的界面

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

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

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

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

【问题讨论】:

  • @Michaël Demey 是的,我已经检查过这些问题。事情是这里的画布,android 的视图和布局将调用所有这些 libgdx 框架的布局。这就是为什么我得到一个黑色的屏幕截图。而且我不知道该怎么办。

标签: android libgdx screenshot screensharing


【解决方案1】:

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

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

【讨论】:

  • Bill 这种方式屏幕截图 isb 被保存在 libgdx 的这个桌面部分上。我怎样才能将它与android同步并保存在我的手机中?
猜你喜欢
  • 1970-01-01
  • 2013-08-14
  • 2021-12-23
  • 2013-11-21
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多