안드로이드 개발 질문/답변
(글 수 45,052)
public class Zoom extends SurfaceView implements Callback {
public Zoom(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
mBitmap = BitmapFactory.decodeFile("/sdcard/Subwaymap_100114.png", options);
setFocusable(true);
mColors = createColors();
int[] colors = mColors;
mViewBitmap = Bitmap.createBitmap(colors, 0, mST, mWidth, mHeight, Bitmap.Config.ARGB_8888);
resize= Bitmap.createScaledBitmap(mViewBitmap, mWidth, mHeight, true);
System.out.println("Create");
//mPaint = new Paint();
//mPaint.setDither(true);
}
private Bitmap mBitmap;
private Bitmap mViewBitmap;
private int mWidth = 0;
private int mHeight = 0;
private Paint mPaint;
private int[] mColors;
private int mST = 0;
private Bitmap resize;
private int[] createColors(){
System.out.println("createColors");
int[] colors = null;
mWidth = mBitmap.getWidth();
mHeight = mBitmap.getHeight();
mST = mWidth + 10; // 넓이보다 10을 크게 설정
colors = new int[mST * mHeight];
for (int y = 0; y < mHeight; y++) {
for (int x = 0; x < mWidth; x++) {
colors[y * mST + x] = mBitmap.getPixel(x, y);
}
}
return colors;
}
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);
System.out.println("Draw");
int winWidth = getWidth();
int winHeight = getHeight();
// 이미지 그리기
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(resize, 0,0, null);
canvas.translate(0, mViewBitmap.getHeight());
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
소스를 통쨰로 다 올렸습니다.
이상하게 OnDraw가 호출이 안됩니다;
public Zoom(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
mBitmap = BitmapFactory.decodeFile("/sdcard/Subwaymap_100114.png", options);
setFocusable(true);
mColors = createColors();
int[] colors = mColors;
mViewBitmap = Bitmap.createBitmap(colors, 0, mST, mWidth, mHeight, Bitmap.Config.ARGB_8888);
resize= Bitmap.createScaledBitmap(mViewBitmap, mWidth, mHeight, true);
System.out.println("Create");
//mPaint = new Paint();
//mPaint.setDither(true);
}
private Bitmap mBitmap;
private Bitmap mViewBitmap;
private int mWidth = 0;
private int mHeight = 0;
private Paint mPaint;
private int[] mColors;
private int mST = 0;
private Bitmap resize;
private int[] createColors(){
System.out.println("createColors");
int[] colors = null;
mWidth = mBitmap.getWidth();
mHeight = mBitmap.getHeight();
mST = mWidth + 10; // 넓이보다 10을 크게 설정
colors = new int[mST * mHeight];
for (int y = 0; y < mHeight; y++) {
for (int x = 0; x < mWidth; x++) {
colors[y * mST + x] = mBitmap.getPixel(x, y);
}
}
return colors;
}
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);
System.out.println("Draw");
int winWidth = getWidth();
int winHeight = getHeight();
// 이미지 그리기
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(resize, 0,0, null);
canvas.translate(0, mViewBitmap.getHeight());
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
소스를 통쨰로 다 올렸습니다.
이상하게 OnDraw가 호출이 안됩니다;