2015-03-03 82 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,就這些了。

相關問題