bboks.net™

이미지 flip 시키기 본문

Mobile Programming/Android

이미지 flip 시키기

bboks.net 2014. 8. 12. 17:25

1. 플립 메소드

public static final int FLIP_VERTICAL = 1;
public static final int FLIP_HORIZONTAL = 2;

private Bitmap flipImage(Bitmap src, int type) {
	// create new matrix for transformation
	Matrix matrix = new Matrix();
	// if vertical
	if (type == FLIP_VERTICAL) {
		// y = y * -1
		matrix.preScale(1.0f, -1.0f);
	}
	// if horizonal
	else if (type == FLIP_HORIZONTAL) {
		// x = x * -1
		matrix.preScale(-1.0f, 1.0f);
		// unknown type
	} else {
		return null;
	}

	// return transformed image
	return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(),
			matrix, true);
}


2. 이미지 플립 시키미(호출쪽)

ImageView imgView = (ImageView) findViewById(R.id.imageView);
imgView.setImageBitmap(flipImage(BitmapFactory.decodeResource(getResources(), R.drawable.img), FLIP_VERTICAL );


[출처] Image Flipping (Mirroring) in ImageView (Android)