0
ImageView를 나침반처럼 돌릴 때 비트 맵 사용에 문제가 있습니다. 비트 맵을 사용하더라도 완벽하게 회전합니다.Android에서 Bitmap을 사용하는 것보다 ImageView를 더 잘 회전 할 수 있습니까?
그러나, 메모리 모니터와 로그 캣 더 깊이보고 후, 나는 흔적의 거대한 덤프가 말하는 얻을 :
나를 위해01-21 21:05:56.556 22147-22147/.../
dalvikvm﹕ GC_FOR_ALLOC freed 11983K, 21% free 56247K/70808K,
paused 15ms, total 15ms
, 그건 좋은 징조하지 않고 내가 비트 맵을 사용하고 때 발생 GC의 피해를 피할 수있는 조언을 해줄 수있는 사람은 누구입니까? 아래 코드는 센서 메서드 "onSensorChanged()"내에서 호출됩니다 (아래 코드, mFragment는 WeakReference, mBitmapOrg는 비트 맵 임). 최적의 선택이라면 안드로이드 NDK를 사용하지 않을 것입니다. 다음은
private void rotateImageView(ImageView imageView, int drawable, float rotate) {
DisplayMetrics mDisplayMetrics = new DisplayMetrics();
mFragment.get().getActivity().getWindowManager().getDefaultDisplay().
getMetrics(mDisplayMetrics);
int width = mBitmapOrg.getWidth(), height = mBitmapOrg.getHeight();
Matrix mMatrix = new Matrix();
rotate = rotate % 360;
mMatrix.postRotate(rotate, width, height);
Bitmap rotatedBitmap = Bitmap.createBitmap(mBitmapOrg, 0, 0, width, height, mMatrix, true);
BitmapDrawable bitmapDrawable = new BitmapDrawable(mFragment.get().getResources(), rotatedBitmap);
imageView.setImageDrawable(bitmapDrawable);
imageView.setScaleType(ImageView.ScaleType.CENTER);
}
는 onSensorChanged된다
@Override
public void onSensorChanged(SensorEvent event)
{
if (mFromLocation == null || mToLocation == null ||
mArrowCompass == null || event == null) return;
switch (event.sensor.getType())
{
case Sensor.TYPE_ACCELEROMETER:
System.arraycopy(event.values, 0, mValuesAccelerometer, 0, 3);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
System.arraycopy(event.values, 0, mValuesMagneticField, 0, 3);
break;
}
boolean success = SensorManager.getRotationMatrix(mMatrixR, mMatrixI,
mValuesAccelerometer,
mValuesMagneticField);
// calculate a new smoothed azimuth value and store to mAzimuth
if (success)
{
SensorManager.getOrientation(mMatrixR, mMatrixValues);
mAzimuth = (float) Math.toDegrees(mMatrixValues[0]);
mAzimuth -= getGeomagneticField(mFromLocation).getDeclination(); // converts magnetic north into true north
mBearTo = mFromLocation.bearingTo(mToLocation);
// If the bearTo is smaller than 0, add 360 to get the rotation clockwise.
if (mBearTo < 0) {
mBearTo = mBearTo + 360;
}
//This is where we choose to point it
mDirectionToDest = (mBearTo - mAzimuth) % 360;
// If the direction is smaller than 0, add 360 to get the rotation clockwise.
if (mDirectionToDest < 0) {
mDirectionToDest = mDirectionToDest + 360;
}
final float mDirection = mDirectionToDest;
rotateImageView(mArrowCompass.get(), R.drawable.compass_arrow, mDirection);
}
}
시도는 = – gio
가 이미지 뷰의 내부 매트릭스를 회전 비트 맵 회전 imageView.getImageMatrix을 (호출하여 그것을 얻을) 및 scaleType를 사용하는 , 작동하지 않았다, 당신은 나를 위해 그 모범을 보여줄 수 있습니까? – pskink
시도 "매트릭스",보기 대신 –