Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) {
if (orientationDegree == 0) {
return bm;
}
Matrix m = new Matrix();
m.setRotate(orientationDegree, (float) bm.getWidth() / 2,
(float) bm.getHeight() / 2);
try {
Bitmap bm1 = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bm1;
} catch (OutOfMemoryError ex) {
}
return null;
}
private void drawInCenter(Canvas canvas, Bitmap bitmap, float left,
float top, String text) {
canvas.drawBitmap(bitmap, left - bitmap.getWidth() / 2,
top - bitmap.getHeight() / 2, null);
}
// 子控件位置改变重新计算角度
private int computeCurrentAngle(float x, float y) {
// 根据圆心坐标计算角度
float distance = (float) Math
.sqrt(((x - mPointX) * (x - mPointX) + (y - mPointY)
* (y - mPointY)));
int degree = (int) (Math.acos((x - mPointX) / distance) * 180 / Math.PI);
if (y < mPointY) {
degree = -degree;
}
if (degree < 0) {
degree += 360;
}
// Log.i("RoundSpinView", "x:" + x + ",y:" + y + ",degree:" + degree);
return degree;
}
// 获取距离圆心的距离
private float getDistance(float x, float y) {
// 根据圆心坐标计算角度
float distance = (float) Math
.sqrt(((x - mPointX) * (x - mPointX) + (y - mPointY)
* (y - mPointY)));
return distance;
}
//点击
private boolean SetClick(float x, float y) {
float distance = getDistance(x, y);
if (mAngle>10||mAngle<-10) {
return false;
}else if(endTime-beginTime>1000){
return false;
}
if (distance < bitmapBig.getWidth() / 2) {
int mod = 0;
if (beginAngle < 90 || 330 < beginAngle) {
mod = (imageIndex+3-1)%3;
}
else if (90 < beginAngle && 210 > beginAngle) {
mod = (imageIndex+3-2)%3;
}
else{
mod = imageIndex;
}
//回调到主界面进行处理。
listener.onModClick(mod);
}
return true;
}
public interface RotateViewListener {
void onModClick(int mode);
void onModChange(int mode);
}
}