我試圖加載存儲在文件系統中的圖像到imageButton中。但它不能正確縮放。該文件在可繪製資源和文件系統中是相同的(t700.png),但結果是不同的。setImageDrawable不能正確縮放,沒有資源圖片
這項工作很好:
button.setImageDrawable(getResources().getDrawable(R.drawable.t700));
這種變化的規模/尺寸並獲得更大的圖像:
String filePath = VideoActivity.this.getFilesDir()+File.separator+EPGApiService.LOGOS_DIR+File.separator+channel.getLogoFile();
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
BitmapDrawable imgDrawable = new BitmapDrawable(this.getResources(),bitmap);
button.setImageDrawable(imgDrawable);
我需要相同的結果..
注: 如果我這樣做
BitmapDrawable logoBitmapDrawableFromDisk = new BitmapDrawable(VideoActivity.this.getResources(),logoBitmap);
BitmapDrawable logoBitmapDrawableFromDisk2 = new BitmapDrawable(logoBitmap);
BitmapDrawable logoBitmapDrawableFromRes = (BitmapDrawable) getResources().getDrawable(R.drawable.t700);
Drawables位圖大小不一樣!
logoBitmapDrawableFromDisk尺寸爲410x123
logoBitmapDrawableFromDisk2尺寸爲205x62
logoBitmapDrawableFromRes尺寸爲820x246
真正的文件是一樣的。我需要這兩種方式的相同大小。
你使用的是什麼版本的android? 'R.drawable.t700'是一個文件或者是另一個可繪製資源的別名? – ramaral
它是指res /可繪製 –
中的t700.png圖像文件,位於文檔:BitmapDrawable(Resources res) 此構造函數在API級別18中已棄用。使用BitmapDrawable(android.content.res.Resources,android.graphics.Bitmap)指定一個位圖來繪製。 –