Android MediaMetadata image on lockscreen is zoomed

梦想与她 提交于 2019-12-24 15:43:53

问题


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);

or

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

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?


回答1:


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 :

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;
}


来源:https://stackoverflow.com/questions/29543418/android-mediametadata-image-on-lockscreen-is-zoomed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!