[英]android - image has different sizes on different phones
我有一个可以与Facebook SDK和google map API一起使用的应用程序。
在HomeActivity
,我获得了用户个人资料图片并将其绘制在Google地图上作为标记。
public void loadProfilePicture(String picUrl, final Location location) {
Picasso.with(getActivity()).load(picUrl).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
drawCanvas(location, bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
}
private void drawCanvas(Location location, Bitmap bitmap) {
photoMarker = getMap().addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude()))
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.anchor(0.5f, 1));
}
我的问题是-当我在其他设备( 例如OnePlusOne和Samsung gt-18190 )上运行该应用程序时,它会在Samsung gt-18190设备上绘制更大的图像(奇怪的是,更小)。
我在loadProfilePicture
方法中检查了picUrl
,它们在chrome上看起来大小相同,但是在不同的设备上大小不同。
我究竟做错了什么?
三星的像素密度是OnePlusOne的一半(〜233ppi与〜401ppi),因此,如果您在两部手机上加载的位图具有相同的分辨率,它将在Samsung上显得更大。
您可以做的是获取毕加索返回的位图,并使用Bitmap.createScaledBitmap函数和具有某些密度独立尺寸的资源文件创建缩放版本。 例如:
在您的资源dimen.xml文件中。 (使用适用于您的应用程序的任何dp值)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="profile_width">200dp</dimen>
<dimen name="profile_height">200dp</dimen>
</resources>
在您的家庭活动中。
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int width = (int) getResources().getDimension(R.dimen.profile_width);
int height = (int) getResources().getDimension(R.dimen.profile_height);
drawCanvas(location, Bitmap.createScaledBitmap(bitmap, width, height, false));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.