锁定屏幕上的Android MediaMetadata图像已缩放 [英] Android MediaMetadata image on lockscreen is zoomed

查看:311
本文介绍了锁定屏幕上的Android MediaMetadata图像已缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

播放媒体时,我可以通过

When playing media, I am able to place media image onto a lockscreen via

RemoteControlClient.MetadataEditor editor = remoteControlClient.editMetadata(true);
editor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, bitmap);

MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap);

但是,如果我使用横向源图像(16:9)并且锁屏方向是potrait,背景图像被缩放(平移和扫描)而不是信箱。有没有我可以用来强制缩放方法的api,或者系统只会这样渲染图像?

however, if I use landscape source image (16:9) and lockscreen orientation is potrait, the background image is zoomed (pan and scan) instead of letter boxed. Is there any api I can use to force the scaling method, or the system will render the image only this way?

推荐答案

我面对同样的问题(在手机锁屏和Android Auto上),我还没有找到解决方案,但我认为你可以做一个技巧:

I have faced the same issue (on phone lockscreen and on Android Auto), I have not found the solution yet but I think that you can do a trick :

添加透明填充顶部和上方的Bitmap以适应锁定屏幕,这里是使您的位图正方形的代码,您可以从中激发您的位图以适应屏幕比例:

Add a transparent padding on top and above to your Bitmap to fit the lock screen, here is the code which makes your bitmap square, you can inspire from it to make your bitmap fit the screen ratio :

public static Bitmap createSquaredBitmap(Bitmap srcBmp) {               

    int dim = Math.max(srcBmp.getWidth(), srcBmp.getHeight());
    Bitmap dstBmp = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(dstBmp);
    canvas.drawColor(Color.TRANSPARENT);
    canvas.drawBitmap(srcBmp, (dim - srcBmp.getWidth()) / 2, (dim - srcBmp.getHeight()) / 2, null);

    return dstBmp;
}

这篇关于锁定屏幕上的Android MediaMetadata图像已缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆