안드로이드 개발 질문/답변
(글 수 45,052)
스크레치 효과를 넣기 위해서
터치시 위치값을 가져고고 그위치 값으로 픽셀 값까지는 가져옵니다.
그런데 그픽셀에 다른 비트맵 픽셀값을 넣고 싶은데요 여기서 막히네요
package com.test.custom;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public class MyView extends View {
private Paint mPaint;
private ArrayList<Vertex> arVertex;
private Bitmap bitmap, bitmap2;
private int xb, yb, color;
public MyView(Context context) {
super(context);
init();
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.img_animal01);
bitmap.setPixel(xb, yb, color);
arVertex = new ArrayList<MyView.Vertex>();
}
public class Vertex {
public Vertex(float ax, float ay, boolean ad) {
x = ax;
y = ay;
Draw = ad;
}
float x;
float y;
boolean Draw;
}
public void onDraw(Canvas canvas) {
bitmap2 = BitmapFactory.decodeResource(getResources(),
R.drawable.bg_scratch);
canvas.drawBitmap(bitmap2, 0, 0, null);
for (int i = 0; i < arVertex.size(); i++) {
if (arVertex.get(i).Draw) {
canvas.drawBitmap(bitmap2, 0, 0, null);
}
}
} // End of if statement
// 터치 이동시마다 정점들을 추가한다.
int mx, my;
public boolean onTouchEvent(MotionEvent event) {
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.img_animal01);
mx = (int) event.getX();
my = (int) event.getY();
Log.i("x좌표================y좌표", "touch x : " + xb + " touch y : " + yb);
if (xb != mx || yb != my) {
xb = mx;
yb = my;
color = bitmap.getPixel(xb, yb);
bitmap2.setPixel(xb, yb, color);
Log.i("픽셀=================", ": " + color);
invalidate();
}
return true;
} // End Of onTouchEvent()
} // End Of class MyView declaration