위에 캔버스를 가지고하는 방법 : 나는 FrameLayout이를 확장하는이 클래스를 수정 한내가 여기에서 가져온 라이브러리 인 내 응용 프로그램에 대한 I 돋보기보기를 사용하고 다른 뷰
https://github.com/nomanr/android-image-magnifier
은 (는 이미지 뷰이었다 이전) 내 FrameLayout에서 작업 할 수 있습니다.
페인트 된 캔버스보기가 해당 사용자 정의보기에 추가 된 모든보기를 유지한다는 점을 제외하면 잘 작동합니다.
추가 된 뷰 앞에 캔버스를 가져 오는 방법은 무엇입니까? 내가 사용하고
사용자 정의 뷰 클래스 :
public class ImageMagnifier extends FrameLayout {
private PointF zoomPos;
private boolean zooming = false;
private Matrix matrix;
private Paint paint;
private Bitmap bitmap;
private BitmapShader shader;
private int sizeOfMagnifier = 300;
int cheight, cwidth;
Context con;
C c = C.getInstance();
public ImageMagnifier(Context context) {
super(context);
init();
con=context;
}
public ImageMagnifier(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
con=context;
}
public ImageMagnifier(Context context, AttributeSet attrs) {
super(context, attrs);
init();
con=context;
}
private void init() {
zoomPos = new PointF(0, 0);
matrix = new Matrix();
paint = new Paint();
cwidth = c.Width * 109/1280;
cheight = cwidth * 134/109;
}
public void otherTouch(int x, int y) {
if (x > c.getwidth1(28) && x < c.getwidth1(921) && y > c.getheight1(135) && y < c.getheight1(560)) {
zoomPos.x = x - 10;
zoomPos.y = y - 75;
zooming = true;
this.invalidate();
} else {
RemoveMagnifire();
}
}
public void RemoveMagnifire() {
zooming = false;
this.invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!zooming) {
buildDrawingCache();
} else {
bitmap = getDrawingCache();
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,Shader.TileMode.CLAMP);
paint.setShader(shader);
matrix.reset();
matrix.postScale(2f, 2f, zoomPos.x-10, zoomPos.y+60);
paint.getShader().setLocalMatrix(matrix);
int width = c.Width;
int height = c.Height;
float leftX = zoomPos.x - ((width * 100)/1280);
float topY = zoomPos.y - ((height * 250)/720);
float rightX = zoomPos.x + ((width * 100)/1280);
float bottomY = zoomPos.y - ((height * 100)/720);
canvas.drawRect(leftX , topY, rightX, bottomY, paint);
}
}
}
수정 된 수업을 게시하여 어떤 의미인지 알 수 있도록하십시오. –
여기 있습니다 : http://pastebin.com/AzcVEWG7 – Prashant
확인은 매우 간단하지만 질문 자체에 클래스를 게시하십시오. 오프 사이트 코드에 링크하지 마십시오. 미래의 사용자는 그것을 볼 수 있어야하고, 그 링크가 죽은 후에는 볼 수 없게됩니다. 감사. –