Tôi muốn Xoay hình ảnh theo một góc độ cụ thể trong android, một số điều như một la bàn ...quay hình ảnh trên một canvas trong android
tôi có mã này ... nó hoạt động trên drawPath() nhưng tôi muốn thay thế đường dẫn và điều Vẽ bằng hình ảnh .. Tôi đã cố gắng tạo một hình ảnh bitmap, DrawBitmapImage, nhưng hình ảnh không Xoay như đường dẫn..Bất cứ trợ giúp nào?
public void draw(Canvas canvas) {
double angle = calculateAngle(currentLongitude, currentLatitude, targetLongitude, targetLatitude);
//Correction;
angle-=90;
//Correction for azimuth
angle-=azimuth;
if((getContext() instanceof Activity) && ((Activity)getContext()).getWindowManager().getDefaultDisplay().getOrientation()==Configuration.ORIENTATION_PORTRAIT)angle-=90;
while(angle<0)angle=angle+360;
Rect rect = canvas.getClipBounds();
int height = rect.bottom-rect.top;
int width = rect.right-rect.left;
int left = rect.left;
int top = rect.top;
if(height>width){
top+=(height-width)/2;
height=width;
}
if(width>height){
left+=(width-height)/2;
width=height;
}
float centerwidth = width/2f;
float centerheight = height/2f;
Paint p = new Paint();
p.setColor(color);
p.setStyle(Paint.Style.FILL);
p.setAntiAlias(true);
float startX = left+(float)(centerwidth+Math.cos(deg2rad(angle))*width/3.0);
float startY = top+(float)(centerheight+Math.sin(deg2rad(angle))*height/3.0);
Path path = new Path();
path.moveTo(
startX,
startY);
path.lineTo(
left+(float)(centerwidth+Math.cos(deg2rad(angle+140))*width/4.0),
top+(float)(centerheight+Math.sin(deg2rad(angle+140))*height/4.0));
path.lineTo(
left+(float)centerwidth,
top+(float)centerheight
);
path.lineTo(
left+(float)(centerwidth+Math.cos(deg2rad(angle+220))*width/4.0),
top+(float)(centerheight+Math.sin(deg2rad(angle+220))*height/4.0)
);
path.lineTo(
startX,
startY
);
canvas.drawPath(path, p);
}
@Jave, tôi nghĩ cách tiếp cận đầu tiên có thể được sử dụng, cụ thể là bạn muốn xoay hình ảnh hoặc bitmap xung quanh trục x và/hoặc trục y vì 'Canvas' không có phương thức xoay khác hiện nó trong mặt phẳng XY. Tôi nghĩ rằng người ta có thể nhận được một đối tượng 'Camera' và thực hiện các phép biến đổi 3D cần thiết và cuối cùng sử dụng' getMatrix' để truyền thể hiện 'Matrix' để có được biểu diễn' Matrix' tương ứng. Cuối cùng, chuyển phương thức 'Matrix' sang' drawBitmap' này. Cụ thể, [ở đây] (http://stackoverflow.com/questions/32554925/android-animate-rotation-of-map-marker-around-x-and-y-axis): Bất kỳ suy nghĩ nào. Cảm ơn! –