1月 132013
 

[java]

public static Bitmap getImgToBitmap(String path, int w, int h) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeFile(path, opts);
int width = opts.outWidth;
int height = opts.outHeight;
float sWidth = 0.f, sHeight = 0.f;
if (width > w || height > h) {
//画像のズーム
sWidth = ((float) width) / w;
sHeight = ((float) height) / h;
}
opts.inJustDecodeBounds = false;
float scale = Math.max(sWidth, sHeight);
opts.inSampleSize = (int)scale;
WeakReference<Bitmap> weak = new WeakReference<Bitmap>(BitmapFactory.decodeFile(path, opts));
return Bitmap.createScaledBitmap(weak.get(), w, h, true);
}

[/java]