[英]How to to fit the image size to device screen size without losing image quality?
嗨,我正在嘗試在Android中做壁紙應用程序。 我無法將圖像設置為設備屏幕尺寸。 當我將其設置為牆紙時,圖像也會失去其質量。 我也嘗試了一些stackoverflow答案,但是這些沒有給我適當的結果。
這是我的代碼:
public void onClick(View arg0) {
WallpaperManager myWallpaperManager= WallpaperManager.getInstance(getApplicationContext());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
try {
Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap();
if(bitmap!=null)
myWallpaperManager.setBitmap(bitmap);
myWallpaperManager.suggestDesiredDimensions(width, height);
Toast.makeText(SingleItemView.this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我在這里做錯了什么?
我想您嘗試將縮略圖(縮放)圖像設置到屏幕上。
試試這個代碼:
Bitmap bitmap = BitmapFactoty.decodeFile(path); // or decodeResource, decodeStream, etc
// depends on your source
代替:
Bitmap bitmap=((BitmapDrawable)imgflag.getDrawable()).getBitmap();
此源必須包含較大的位圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.