我在画布上旋转位图时遇到问题,我正在使用 canvas.drawline 在画布上绘制位图并使用以下代码旋转图像
它旋转但现在显示两个图像?如何从画布中删除以前的图像?该怎么办?
bitmap = Bitmap.createBitmap((int) /*getWindowManager()
.getDefaultDisplay().getWidth()*/600, (int) /*getWindowManager()
.getDefaultDisplay().getHeight()*/600, Bitmap.Config.ARGB_8888 );
Canvas canvas = new Canvas(bitmap);
drawingImageView.setVisibility(View.VISIBLE);
drawingImageView.setImageBitmap(bitmap);
// canvas.rotate(90);
for(int i=0;i<SettingsStaticData.arrX1_crossPoint.size();i++)
{
canvas.drawLine(new Float(SettingsStaticData.arrX1_crossPoint.get(i)),new Float(SettingsStaticData.arrY1_crossPoint.get(i)),new Float(SettingsStaticData.arrX2_crossPoint.get(i)) ,new Float(SettingsStaticData.arrY2_crossPoint.get(i)), paint);
}
paint.setStrokeWidth((float) 0.9);
paint.setStyle(Paint.Style.FILL);
// paint.setColor(Color.RED);
paint.setColor(Color.parseColor("#800080"));
for(int i=0;i<arrXX.size()-1;i++)
{
if(i==arrXX.size()-2)
{
canvas.drawLine(new Float(arrXX.get(0)),new Float(arrYY.get(0)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
}
else
{
canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
}
}
// canvas.drawColor(0, Mode.CLEAR);
Matrix matrix = new Matrix();
matrix.reset();
matrix.postTranslate(-bitmap.getWidth() / 2-500, -bitmap.getHeight() / 2-500); // Centers image
matrix.postRotate(180);
//matrix.postTranslate(px, py);
canvas.drawBitmap(bitmap, matrix, null);