あなたが適切にビットマップを作成していないように見えますが、私はあなたの位置にあった場合、私はそうのようなスケールのビットマップを作成します。
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(
bm, 0, 0, width, height, matrix, false);
bm.recycle();
return resizedBitmap;
}
そして、そのようなImageViewのに設定します。
mImg.setImageBitmap(img);
全体的に、それは次のようになります。
public void loadImage() {
Picasso.with(getBaseContext()).load("image url").into(new Target() {
// ....
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
// Pick arbitrary values for width and height
Bitmap resizedBitmap = getResizedBitmap(bitmap, newWidth, newHeight);
mImageView.setBitmap(resizedBitmap);
}
// ....
});
}
}
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(
bm, 0, 0, width, height, matrix, false);
bm.recycle();
return resizedBitmap;
}
しかし、私はあなたがを使用して質問全体は、通常は非常に特殊なケースです。イメージを表示する同じクラスのシングルトンをPicasso
と呼ぶべきです。
Picasso.with(mContext)
.load("image url")
.into(mImageView);
おかげで、私はすでに(リサイズのための場所でメソッドを持ってhttp://developer.android.com/training/displaying-bitmaps/load-bitmap:通常、これはそうのよう
Adapter
(多分RecyclerViewアダプタ)であります.html)。私はちょうどImageViewに直接ではなく、ビットマップにURLから画像をロードする必要があり、上記のコメントからそれを考え出した。どうもありがとう。 – Alexなぜ非同期タスクを使用して画像をロードしていますか? .into(mImageView、new Callback <> {...})にコールバックを実装するだけで済みます。 – AndyRoid
実際、リソースフォルダから読み込むのではなく、実際にアダプタ(RecycleView)に渡されるビットマップにイメージを読み込むための簡単な方法を試していました。私はここで説明した問題をデバッグしようとしています。http://stackoverflow.com/questions/32554358/encountering-lag-when-updating-a-cardview-item-in-a-recycleview私はおそらくそれが表示されるクラスでイメージを読み込もうとします。しかし、私はピカソはアクティビティクラスでのみ使用できますが、少なくともそれは私がいくつかの投稿から理解したものです。そして私はContextをAdapterクラスに渡す必要があると思います。 – Alex