我为多个位图,矩阵和颜料制作了arraylists,我想在我的主线程中动态更改它们。这是我的drawview(剪切一些代码来缩短它):
public DrawView(Context context, AttributeSet attrs){
bitmapArray.add(bitmap1);
Matrix matrix2 = new Matrix();
matrixArray.add(matrix2);
Paint paint = new Paint();
paintArray.add(paint);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0; i < 50; i++) {
canvas.drawBitmap(bitmapArray.get(i), matrixArray.get(i), paintArray.get(i));
}
}
public void translate(int Num, float x, float y){
matrixArray.get(Num).postTranslate(x,y);
}
我喜欢的是从我的主线程中调用drawview.translate,如下所示:
drawView.translate(Num, image.getX(), image.getY()); //image is a moving imageview
我无法找到使用主线程来控制绘制位图的内容,所以如果有人能解释我会非常感激
答案 0 :(得分:0)
我终于找到了一种方法来绘制我的位图并按照我的命令移动/旋转它:
在我的OnDraw(){
中canvas.drawBitmap(bitmap1, null, rectf, sPaint);
使用rectF移动,并旋转:
rotation = ((float) Math.toDegrees(Math.atan2((fingery - rectf.centerY()),(fingerx - rectf.centerX())));
matrix.setRotate(rotation2+90, rectf.centerX(), rectf.centerY());
bitmap1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
当我的位图旋转时,我遇到了麻烦,它改变了尺寸。我用它修复了它:
rectf.right = rectf.centerX() + bitmap1.getWidth()/2;
rectf.left = rectf.centerX() - bitmap1.getWidth()/2;
rectf.top = rectf.centerY() - bitmap1.getHeight()/2;
rectf.bottom = rectf.centerY() + bitmap1.getHeight()/2;
我希望这可以帮助一些人!