ImageView中的drawLine(),其中笔画宽度为SeekBar

时间:2013-03-01 04:31:59

标签: android android-imageview seekbar

我正在使用ImageView进度更改事件在SeekBar中画线。如果SeekBar以递增方式更改,则似乎正常。在减少搜索栏进度的同时,保留已绘制的线。如果减少进度,如何从SeekBar进度更改事件事件中以适当的笔划绘制线条。我尝试将ImageView的drawable设置为null,并将位图图像设置为null,仍然面临错误。

@Override       
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
    imageCanvas.drawLine(0, 0, 100, 100, paint);                 
    mStrokeWidth = (float)progress;
    imageView.setImageDrawable(null);
    imageView.setImageBitmap(null);
    paint.setColor(mStrokeColor);
    paint.setStrokeWidth(mStrokeWidth);
    imageCanvas.drawLine(20, 20, 100, 100, paint);
    imageView.setImageBitmap(bitmap);
}

1 个答案:

答案 0 :(得分:0)

修复了创建新位图并在onProgressChanged()方法中将其分配给画布的问题。

@Override       
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) 
{
  bitmap = Bitmap.createBitmap((int)imageViewSize , (int) imageViewSize, Bitmap.Config.ARGB_8888);
  imageCanvas = new Canvas(bitmap);
  imageCanvas.drawLine(0, 0, 100, 100, paint);                 
  mStrokeWidth = (float)progress;
  imageView.setImageDrawable(null);
  imageView.setImageBitmap(null);
  paint.setColor(mStrokeColor);
  paint.setStrokeWidth(mStrokeWidth);
  imageCanvas.drawLine(20, 20, 100, 100, paint);
  imageView.setImageBitmap(bitmap);
}