我想在社交应用上发布我的游戏的屏幕截图。我使用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 sdk用于Facebook。我只想简单的Android Intent来分享Screen。请帮助我。
答案 0 :(得分:1)
com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap适合我。