メソッドを使用してURLからイメージをロードし、Bitmapオブジェクトに格納しています。それから私はそのサイズを縮小する。縮小された画像サイズを取得した後、私は自分のレイアウトのImageView
に表示しています。今私は、画像のサイズが縮小されたかどうかを知りたいです。それをどうやって確認できますか?ビットマップサイズをAndroidで縮小した後に知る方法は?
public class ReduceImageActivity extends Activity {
String image_URL = "http://pennapps.com/biblioteka/images/C.jpg";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView bmImage = (ImageView) findViewById(R.id.imageView1);
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bm = LoadImage(image_URL, bmOptions);
getResizedBitmap(bm, 200, 200);
System.out.println("after resizing it"+bm);
bmImage.setImageBitmap(getResizedBitmap(bm, 200, 200));
}
private Bitmap LoadImage(String URL, BitmapFactory.Options options) {
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in, null, options);
in.close();
} catch (IOException e1) {
}
return bitmap;
}
private InputStream OpenHttpConnection(String strURL) throws IOException {
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
} catch (Exception ex) {
}
return inputStream;
}
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
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);
System.out.println("in getresizebitmap"+resizedBitmap.toString());
return resizedBitmap;
}
}
CPUメモリを使用しないようにうまく動作しますが、上記のようにCPUメモリを使用すると感謝します。 –