0

我想在社交应用上发布我的游戏截图。我使用 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 。请帮帮我。

4

1 回答 1

1

com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap 对我有用。

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

于 2015-04-24T09:26:45.990 回答