嘿,我需要在我的应用程序中缩放位图,但是缩放速度太慢,有时我会在相反的方向上得到这些随机缩放事件。这是我的 ondraw 方法:
public void onDraw(Canvas canvas) {
mBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ucsbmap);
canvas.drawBitmap(mBitmap, matrix, mPaint);
}
和我的 onScale 方法(处理位图缩放的 SimpleOnScaleGestureListener 的一部分)
public boolean onScale(ScaleGestureDetector detector) {
float scaleFactor = detector.getScaleFactor();
float x = detector.getFocusX();
float y = detector.getFocusY();
matrix.setScale(scaleFactor, scaleFactor, x, y);
repaint();
return true;
}
谢谢。
最佳答案
问题在缩放中并不实际。您在 onDraw
方法中访问光盘 (BitmapFactory.decodeResource
) - 这真的很慢。
将以下代码移至构造函数:
mBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ucsbmap);
关于android - 如何加快android中的缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10678247/