프로그램/Android

안드로이드 그래프 이미지 돌리기

잡식성초보 2016. 2. 19. 17:48

private void PrintGraphDrawing(float now, float target, int id) {


Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.graph_bg);// 뒤에깔 배경

Bitmap bitnow = 

BitmapFactory.decodeResource(getResources(), R.drawable.graph__s);//배경앞에 깔릴 이미지

Bitmap targetbit = BitmapFactory.decodeResource(getResources(), R.drawable.graph_g);// 배경앞에 깔릴 다른 이미지


Rect src = new Rect();

Rect dst = new Rect();


int w = bit.getWidth();

int h = bit.getHeight();

int destx = 0;

int desty = 0;


Bitmap rounder = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_555);


Canvas nowCanvas = new Canvas(rounder);


src.top = 0;

src.left = 0;

src.right = w;

src.bottom = h;


dst.top = desty;

dst.left = destx;

dst.right = destx + w;

dst.bottom = desty + h;


nowCanvas.drawBitmap(bit, src, dst, null);


w = targetbit.getWidth();

h = targetbit.getHeight();


Canvas targetCanvas = new Canvas(rounder);

Path mPath = new Path(); // 각도 주는 클래스

BitmapDrawable targetDraw = new BitmapDrawable(mContext.getResources(), targetbit);

targetDraw.setBounds(0, 0, w, h);

targetCanvas.translate(0, 0);

mPath.reset();


RectF oval = new RectF(0, 0, w, h); // 원그리는 클래스


mPath.moveTo(w / 2, h / 2);

mPath.arcTo(oval, 90, target);


targetCanvas.clipPath(mPath);

targetDraw.draw(targetCanvas);


w = bitnow.getWidth();

h = bitnow.getHeight();


BitmapDrawable nowDraw = new BitmapDrawable(mContext.getResources(), bitnow);

nowDraw.setBounds(0, 0, w, h);

nowCanvas.translate(0, 0);

mPath.reset();


oval = new RectF(0, 0, w, h);


mPath.moveTo(w / 2, h / 2);

mPath.arcTo(oval, 90, now);


nowCanvas.clipPath(mPath);

nowDraw.draw(nowCanvas);


ImageView imgV = (ImageView) mView.findViewById(id);


imgV.ImageBitmap(rounder);

}

반응형