뷰 클레스 입니다

public class ScratchView4 extends View {
private int radius = 60; // 터치 지점으로 부터 반경.
private int pixelArray[]; // 터치한 지점의 픽셀 값을 저장할 배열
private int currentPixelArray[]; // 라운드 처리를 위해 원본 픽셀값을 저장할 배열

private Bitmap currentBitmap; // 현재 화면에 보여지고 있는 비트맵
private Bitmap newBitmap; // 현재 비트맵이 지워지고 보여질 비트맵
private Bitmap maskBitmap; // 터치한 곳의 픽셀을 변경할 때 사각형 형태를 원형태로 변경할 때 사용할 마스크
private Bitmap eraserBitmap;// 지우개 사용 시 현상태 가져올비트맵
private Paint currentBitmapPaint; // 비트맵을 그릴 페인트

private boolean isFirst; // 최초 실행했는지 판단하는 플래그
private int pen1x[] = { 15, 30, 45, 30, 15 };
private int pen1y[] = { 5, 5, 55, 55, 5 };
private int starx[] = { 0, 15, 9, 26, 42, 36, 53, 33, 25, 18, 0 };
private int stary[] = { 18, 31, 48, 38, 49, 32, 17, 17, 0, 17, 18 };
private int heartx[] = { 25, 23, 19, 9, 5, 2, 0, 0, 5, 25, 47, 52, 52, 50,
47, 43, 33, 29, 25 };
private int hearty[] = { 6, 2, 0, 0, 2, 5, 10, 15, 27, 52, 27, 15, 10, 5,
2, 0, 0, 2, 6 };

// 작은하트
// private int heartx[] = { 20, 18, 15, 12, 9, 7, 4, 2, 0, 0, 4, 20, 36, 40,
// 40, 38, 36, 33, 31, 27, 26, 23, 20 };
// private int hearty[] = { 7, 4, 1, 0, 0, 1, 3, 5, 9, 14, 23, 40, 23, 14,
// 9,
// 5, 3, 1, 0, 0, 1, 4, 7 };
/**
* 생성자
* 
* @param context
*/
public ScratchView4(Context context) {
super(context);
pixelArray = new int[radius * radius]; // 터치한
// 곳의
// 픽셀
// 저장할
// 배열
// 생성
currentPixelArray = new int[radius * radius]; // 라운드 처리를 위해 원본 픽셀 값 저장할
// 배열
isFirst = true; // 최초 실행되었다고 플래그 값 설정
}

/**
* 뷰의 사이즈가 정해지면 뷰의 크기 만큼 비트맵을 만들기 위해 onWindowFocusChanged 메소드를 오버라이드 함.
*/
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if (isFirst) // 최초 실행이면
initSource(); // 비트맵을 초기화 한다
ScratchMenu4.penck = true;
ScratchMenu4.save = false;
}

private static String mDirPath = Environment.getExternalStorageDirectory()
.getAbsoluteFile() + "/ScratchBook";

/**
* 비트 맵을 초기화 한다
*/

public void initSource() {
isFirst = false; // 최초 실행이 아니라고 플래그 설정

int w = getWidth(); // 뷰의 가로 크기. onWindowFocusChanged메소드가 불려지고 나서 뷰의 크기가
// 정해진다
int h = getHeight(); // 뷰의 세로 크기

Options opts = new Options(); // 비트맵 생성 옵션
opts.inPurgeable = true; // 메모리 정리될 수 있게 설정
if (ScratchMenu4.penck) {
// 지워질 그림에 대한 이미지 저장
Bitmap temp = BitmapFactory.decodeResource(getResources(),
R.drawable.bg_scratch, opts);
currentBitmap = Bitmap.createScaledBitmap(temp, w, h, true);

eraserBitmap = Bitmap.createScaledBitmap(temp, w, h, true);
// 칠해질 그림에 대한 이미지 저장
// *************스위치로 이미지 변경 동물 사물 과일 구분 지어줘야함***************
temp = BitmapFactory.decodeResource(getResources(),
ScratchBookData.bg_pattern[ScratchMenu4.bg_pattern], opts);
// *************스위치로 이미지 변경 동물 사물 과일 구분 지어줘야함***************
newBitmap = Bitmap.createScaledBitmap(temp, w, h, true);
}
Paint p = new Paint(); // 마스크 용 페인트
p.setStyle(Style.FILL); // 채우기
p.setColor(Color.BLACK); // 검은색

maskBitmap = Bitmap.createBitmap(radius, radius, Config.ARGB_8888); // 마스크
// 비트맵
// 생성
Canvas c = new Canvas(maskBitmap); // 마스크 비트맵에 그릴 캔버스 생성

c.drawRect(0, 0, radius, radius, p); // 마스크
// 전체를
// 검은색으로
p.setColor(Color.WHITE); // 페인트 색 흰색
Path star = new Path();

switch (ScratchMenu4.paintsize) {
case 1:
star.moveTo(pen1x[0], pen1y[0]);
for (int i = 0; i < pen1x.length; i++) {
star.lineTo(pen1x[i], pen1y[i]);
}

c.drawPath(star, p);

break;
case 2:
c.drawCircle(radius / 2, radius / 2, radius / 4, p);
break;
case 3:
// 원모양
c.drawCircle(radius / 2, radius / 2, radius / 8, p);// 가운데
// 원은
// 흰색으로
// 그림
// 원모양 끝
break;
case 4:
// 하트모양
star.moveTo(heartx[0], hearty[0]);
for (int i = 0; i < hearty.length; i++) {
star.lineTo(heartx[i], hearty[i]);
}

c.drawPath(star, p);
// 하트모양끝
break;
case 5:
// 별모양
star.moveTo(starx[0], stary[0]);
for (int i = 0; i < starx.length; i++) {
star.lineTo(starx[i], stary[i]);
}

c.drawPath(star, p);
// 별모양 끝
break;

}
// 사진 저장 클릭
if (ScratchMenu4.save) {
SaveBitmapToFileCache(currentBitmap, mDirPath);
Toast.makeText(getContext(), "사진이 저장되었습니다", Toast.LENGTH_SHORT)
.show();

}
currentBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // 페인트 생성
}

private void SaveBitmapToFileCache(Bitmap bitmap, String strFilePath) {
File fileCacheItem = new File(strFilePath);

OutputStream out = null;
Log.i("1", strFilePath);
try {
if (!fileCacheItem.exists()) {

fileCacheItem.mkdirs();

}
String path = mDirPath + "/n" + System.currentTimeMillis() + ".jpg";

out = new FileOutputStream(path);

bitmap.compress(CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void checkFolder(final String dirPath) {

File path = new File(dirPath);
if (!path.isDirectory()) {
path.mkdirs();
}
}

/**
* 현재 비트맵에 새로운 비트맵의 픽셀 값을 설정한다.
* 
* @param x
*            - 터치한 좌표
* @param y
*            - 터치한 좌표
*/

private void scratchBitmap(float x, float y) {
newBitmap.getPixels(pixelArray, 0, radius, (int) x - radius / 2,
(int) y - radius / 2, radius, radius); // 새로운
// 비트맵의
// 픽셀 값을
// 가져온다
currentBitmap.getPixels(currentPixelArray, 0, radius, (int) x - radius
/ 2, (int) y - radius / 2, radius, radius); // 라운드 처리를 위해 현재
// 비트맵의 픽셀값을 가져온다

setRoundArea(); // 라운드 형태로 픽셀값을 설정

currentBitmap.setPixels(pixelArray, 0, radius, (int) x - radius / 2,
(int) y - radius / 2, radius, radius); // 현재 비트맵에
// 픽셀값을 설정한다

invalidate(); // 화면 새로 고침

}

// 지우개 비트맵
private void eraserBitmap(float x, float y) {

// TODO Auto-generated method stub
currentBitmap.getPixels(pixelArray, 0, radius, (int) x - radius / 2,
(int) y - radius / 2, radius, radius); // 새로운
// 비트맵의
// 픽셀 값을
// 가져온다
eraserBitmap.getPixels(currentPixelArray, 0, radius, (int) x - radius
/ 2, (int) y - radius / 2, radius, radius); // 라운드 처리를 위해 현재
// 비트맵의 픽셀값을 가져온다

setRoundArea(); // 라운드 형태로 픽셀값을 설정

currentBitmap.setPixels(pixelArray, 0, radius, (int) x - radius / 2,
(int) y - radius / 2, radius, radius); // 현재 비트맵에
// 픽셀값을
// 설정한다
invalidate(); // 화면 새로 고침
}

/**
* 스크래치되는 부분을 둥글게 만든다.
*/
private void setRoundArea() {
for (int i = 0; i < pixelArray.length; i++) {
int maskColor = maskBitmap.getPixel(i % radius, i / radius); // 마스크를
// 검사하여
if (maskColor == Color.BLACK) { // 검은색 부분. 라운드 처리할 부분
pixelArray[i] = currentPixelArray[i]; // 원래 픽셀로 돌려서 라운드 형태로 만듬
}
}
}

@Override
public void onDraw(Canvas canvas) {

canvas.drawBitmap(currentBitmap, 0, 0, currentBitmapPaint); // 현재
// 비트맵을
// 그린다

}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) // 터치 다운이면 이벤트 계속 받게
// true를 리턴
{
float x = event.getX(); // 현재 좌표
float y = event.getY(); // 현재 좌표

// 터치한 곳의 좌표가 픽셀을 가져오는 크기보다 크거나 작으면 에러가 발생하므로 좌표값을 보정함
if (x < radius / 2)
x = radius / 2;
else if (x > getWidth() - radius / 2)
x = getWidth() - radius / 2;

if (y < radius / 2)
y = radius / 2;
else if (y > getHeight() - radius / 2)
y = getHeight() - radius / 2;
if (ScratchMenu4.eraser) {
eraserBitmap(x, y);
} else {

scratchBitmap(x, y); // 터치한 곳의 비트맵의 픽셀값을 변경한다.
}
return true;
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
float x = event.getX(); // 현재 좌표
float y = event.getY(); // 현재 좌표

// 터치한 곳의 좌표가 픽셀을 가져오는 크기보다 크거나 작으면 에러가 발생하므로 좌표값을 보정함
if (x < radius / 2)
x = radius / 2;
else if (x > getWidth() - radius / 2)
x = getWidth() - radius / 2;

if (y < radius / 2)
y = radius / 2;
else if (y > getHeight() - radius / 2)
y = getHeight() - radius / 2;

if (ScratchMenu4.eraser) {
eraserBitmap(x, y);
} else {

scratchBitmap(x, y); // 터치한 곳의 비트맵의 픽셀값을 변경한다.
}
}
return super.onTouchEvent(event);
}


아그리고 한가지더 질문 드릴깨요 
제가 모양을 줄려고 하거든요 그런데 원 모양 같은 경우 작게 해서 할려하는데 범위가 60으로 잡혀 있어서 원을 작게해서 그리게되면 스크레치를 했을때 반지름이 뷰에서 스크레치가 적용 안되는 부분이 생기더라구요 이걸 해결할려고 범위를 줄여줘 봤는데 처음 배열을 생성 하는곳에서 문제가 발생했습니다.. 왜그런지는 알겠는데 사이즈를 작게하더라도 적용 안되는부분이 안생기도록 할려면 어떻게 해야하나요 ..()