2015-03-03 78 views
0

我最近开始使用ImageViewZoom (https://github.com/sephiroth74/ImageViewZoom) 并且我要做的是在此视图中使用的位图上不时绘制一些行。如何在ImageViewZoom中使用的位图上绘制线条?

我试图以下面的方式做到这一点,但结果是视图不再能够缩放。

protected void onDraw(Canvas canvas) 
{ 
    // TODO Auto-generated method stub 
    super.onDraw(canvas); 

    Canvas bmp_canvas = new Canvas(bmp);//bmp is the original bitmap 

    Paint paint = new Paint(); 

    //Draw map 
    paint. setColor(Color.BLUE); 
    paint. setStrokeWidth(10); 
    int i; 
    for(i=0; i<toDraw.size();i++) 
    { 
     Segment now = toDraw.get(i); //toDraw is a List and stores the lines 

     PointType tmp_start = now.s; 
     PointType tmp_end = now.e; 

     bmp_canvas.drawLine((float)tmp_start.x, (float)tmp_start.y, 
       (float)tmp_end.x, (float)tmp_end.y, paint); 
    } 

    Matrix matrix = getImageViewMatrix(); 
    setImageBitmap(bmp, matrix, ZOOM_INVALID, ZOOM_INVALID);   
    return; 
} 

那么这样做的正确方法是什么?非常感谢你!

回答

0

嗯,我自己解决了!

我做到了,通过以下方式:

public void drawMap(Bitmap bmp) //a new function outside of onDraw() 
{ 
    Bitmap now_bmp = Bitmap.createBitmap(bmp); 
    Canvas canvas = new Canvas(now_bmp); 
    Paint paint = new Paint(); 

    //Draw map 
    paint. setColor(Color.BLUE); 
    paint. setStrokeWidth(10); 
    int i; 
    for(i=0; i<toDraw.size();i++) 
    { 
     Segment now = toDraw.get(i); 

     PointType tmp_start = now.s; 
     PointType tmp_end = now.e; 

     canvas.drawLine((float)tmp_start.x, (float)tmp_start.y, 
       (float)tmp_end.x, (float)tmp_end.y, paint); 
    } 

    Matrix matrix = getDisplayMatrix(); 
    setImageBitmap(now_bmp, matrix, ZOOM_INVALID, ZOOM_INVALID);  
} 

总之,只要创建与原点位图一个画布,然后绘制了东西,结果将存储在该位图,并获得当前矩阵,并将新的位图设置为ImageViewZoom,就这些了。

相关问题