簡単な画像処理
2309 ワード
反転であり、反転ではないことに注意してください.
/**
*
*
* @author [email protected]
*
*/
public class ImageHandler {
/**
*
*
* @param bmp
*
* @param degree
* , ,
* @return
*/
public static Bitmap rotateBitmap(Bitmap bmp, float degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
/**
*
*
* @param bm
* @param scale
* ,
* @return
*/
public static Bitmap resizeBitmap(Bitmap bm, float scale) {
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
}
/**
*
*
* @param bm
* @param w
*
* @param h
*
* @return
*/
public static Bitmap resizeBitmap(Bitmap bm, int w, int h) {
Bitmap BitmapOrg = bm;
int width = BitmapOrg.getWidth();
int height = BitmapOrg.getHeight();
float scaleWidth = ((float) w) / width;
float scaleHeight = ((float) h) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(BitmapOrg, 0, 0, width, height, matrix, true);
}
/**
*
*
* @param bm
* @param flag
* 0 ,1
* @return
*/
public static Bitmap reverseBitmap(Bitmap bmp, int flag) {
float[] floats = null;
switch (flag) {
case 0: //
floats = new float[] { -1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f };
break;
case 1: //
floats = new float[] { 1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f };
break;
}
if (floats != null) {
Matrix matrix = new Matrix();
matrix.setValues(floats);
return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
return null;
}
}