Code example for Matrix

Methods: getValues, set, setScale, setValues

0
	} 
 
	public void zoomImageToWindow() { 
		if (bm.getWidth() < width && bm.getHeight() < height) {
			// matrix.reset(); 
			matrix.setScale(1f, 1f);
			bx = bm.getWidth();
			by = bm.getHeight();
		} else { 
			float scale = Math.min((float) width / (float) bm.getWidth(),
					(float) height / (float) bm.getHeight());
			FLog.d("scale=" + scale);
			matrix.setScale(scale, scale);
			bx = bm.getWidth() * scale;
			by = bm.getHeight() * scale;
		} 
 
		// 画像をView中央にセット 
		float[] values = new float[9];
		matrix.getValues(values);
		values[Matrix.MTRANS_X] = (width - bx) / 2;
		values[Matrix.MTRANS_Y] = (height - by) / 2;
		matrix.setValues(values);
	} 
 
	public void setImageBitmap(Bitmap bm) {
		super.setImageBitmap(bm);
		this.bm = bm;
 
		// フィット+中央配置 
		rotated = false;
		matrix.set(moveMatrix);
		zoomImageToWindow(); 
		FLog.d("bx=" + bx + " by=" + by);
		setImageMatrix(matrix);
	}