我是Android的新手,目前正在对Android进行一些研究 . 我在图像顶部绘制一条线或另一个对象时遇到问题 .

我的情况是,我正在使用 setImageBitmap 方法在 imageView 上绘制图像 . 现在我要在它上面添加一行或另一个对象 . 我发现有几篇文章描述我可以覆盖 onDraw 方法,但是当我这样做并使用 canvas.drawBitmap 方法绘制我的图像时,我的 imageView 上有两个图像 . 他们在彼此之上画画 .

我怎样才能只绘制一张图片?

任何线索,或者描述这个的链接?

这里的代码:

public void draw(){

// Declaration output pixels vector
    int[] outputPixels = new int[mImage.getDataLength()];

    // Get the gray scale window width
    int windowWidth = mDICOMViewerData.getWindowWidth();

    // Compute the window offset x the number of gray levels (256)
    int windowOffset = ((2 * mDICOMViewerData.getWindowCenter() - windowWidth)) / 2;

    switch(mDICOMViewerData.getCLUTMode()) {

    case CLUTMode.NORMAL:
        computeGrayscaleRGBImage(windowWidth, windowOffset, outputPixels);
        break;

    case CLUTMode.INVERSE:
        computeInverseGrayscaleRGBImage(windowWidth, windowOffset, outputPixels);
        break;

    case CLUTMode.RAINBOW:
        computeRainbowRGBImage(windowWidth, windowOffset, outputPixels);
        break;

    };

    // Create the bitmap
    Bitmap imageBitmap = Bitmap.createBitmap(outputPixels, mImage.getWidth(),
            mImage.getHeight(), Bitmap.Config.ARGB_8888);

    // Check if image is to be rotated 90 degrees
    if (mIsRotate) {
        Matrix m = new Matrix();
        m.postRotate(90);
        imageBitmap = Bitmap.createBitmap(imageBitmap,
                0,  0, mImage.getWidth(), mImage.getHeight(), 
                m, true);
    }


    // Set the image
    setImageBitmap(imageBitmap);

}

这些代码是从另一个类调用的 .

这里是onDraw方法的覆盖

public void onDraw(Canvas canvas){short toolMode = mDICOMViewerData.getToolMode(); if(toolMode == ToolMode.MEASURE){if(this.getImage()!= null){for(Point point:points){canvas.drawCircle(point.x,point.y,1,paint); }

int[] outputPixels = new int[mImage.getDataLength()];

            // Get the gray scale window width
            int windowWidth = mDICOMViewerData.getWindowWidth();

            // Compute the window offset x the number of gray levels (256)
            int windowOffset = ((2 * mDICOMViewerData.getWindowCenter() - windowWidth)) / 2;

            switch(mDICOMViewerData.getCLUTMode()) {

            case CLUTMode.NORMAL:
                computeGrayscaleRGBImage(windowWidth, windowOffset, outputPixels);
                break;

            case CLUTMode.INVERSE:
                computeInverseGrayscaleRGBImage(windowWidth, windowOffset, outputPixels);
                break;

            case CLUTMode.RAINBOW:
                computeRainbowRGBImage(windowWidth, windowOffset, outputPixels);
                break;

            };

            // Create the bitmap
            Bitmap imageBitmap = Bitmap.createBitmap(outputPixels, mImage.getWidth(),mImage.getHeight(), Bitmap.Config.ARGB_8888);

            //drawing image here

            canvas.drawBitmap(imageBitmap, 153, 0, null);
            Paint paint = new Paint();
            paint.setColor(Color.RED);
            canvas.drawLine(0, 0, 400, 400, paint);

            super.onDraw(canvas);
        }
    }
}