簡體   English   中英

libGDX:如何告訴核心游戲getIconImageUri()並將其用作我的游戲中的Image actor

[英]libGDX: How can I tell core game getIconImageUri() and use it as Image actor into my game

我在核心項目上創建了IGoogleServices接口:

public interface IGoogleServices {    
    .....
    public String getPlayerName();
}

然后,將以下代碼放入android項目的MainActivity的Implementaion方法中:

private String name;
@Override
public String getPlayerName() {
    runOnUiThread(new Runnable() {
        public void run() {
            name = Games.Players.getCurrentPlayer(_gameHelper.getApiClient()).getDisplayName();
        }
    });
    return name;
}

這是告訴MyGame玩家名稱為String簡單方法:

lblPlayerName = new Label("" + googleServices.getPlayerName(), style);
stage.addActor(lblPlayerName);

但是我不能在圖像情況下做到這一點。

在之前的String情況下,我嘗試在image情況下進行了此操作:

private Uri imgUri;
@Override
public void requestImgProfile() {
    runOnUiThread(new Runnable() {
        public void run() {
            imgUri = Games.Players.getCurrentPlayer(_gameHelper.getApiClient()).getIconImageUri();
            ImageManager manager = ImageManager.create(MainActivity.this);
            manager.loadImage(new ImageManager.OnImageLoadedListener() {
                public void onImageLoaded(Uri arg0, Drawable drawable, boolean arg2) {
                        try {
                            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                            FileOutputStream out = new FileOutputStream(imagePath);;
                            out = openFileOutput(imgUri + ".png", Context.MODE_MULTI_PROCESS);
                            bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                            out.flush();
                            out.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }, imgUri);
            };
        });
    }

我的imgUri是:

content://com.google.android.gms.games.background/images/26s5523b/2633

我可以告訴MyGame和libGDX庫可以使用的類類型(例如String )是什么?

如果您具有圖片URI,則可以通過以下方式獲取位圖:

Uri imgUri;
Bitmap bitmap = null;
try {
    InputStream inputStream = getContentResolver().openInputStream(imgUri);
    bitmap = BitmapFactory.decodeStream(inputStream);
} catch (FileNotFoundException e) {
}

無論是file:// URI還是content:// URI,此方法都有效。

然后使用諸如此答案之類的解決方案將位圖轉換為libGDX可用的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM