【问题标题】:how to rotate image using latitude and longitude如何使用纬度和经度旋转图像
【发布时间】:2015-01-22 02:25:28
【问题描述】:

你好,我想按纬度和经度旋转图像视图,假设我有

lat/LNG: (33.6343541968021,73.06278146803379)

现在我想让我的图像视图(针)指向这个位置,我该怎么做? 我正在这样做

 public void onSensorChanged(SensorEvent event) {


                float degree = Math.round(event.values[0]);


        RotateAnimation ra1 = new RotateAnimation(
                currentDegree, 
                -degree,
                Animation.RELATIVE_TO_SELF, 0.5f, 
                Animation.RELATIVE_TO_SELF,
                0.5f);

        // how long the animation will take place
        ra1.setDuration(0);

        // set the animation after the end of the reservation status
        ra1.setFillAfter(true);
        compass_img.startAnimation(ra1);
        currentDegree= -degree;}

我正在使用方向传感器

【问题讨论】:

    标签: android latitude-longitude android-orientation image-rotation compass-geolocation


    【解决方案1】:

    试试这个方法

    // Get the image we want to work with from a URL
    Bitmap myBitmap = BitmapFactory.decodeStream(downloadImageFromWeb());
    
    // or just load a resource from the res/drawable directory:
    Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android1);
    
    // find the width and height of the screen:
    Display d = getWindowManager().getDefaultDisplay();
    int x = d.getWidth();
    int y = d.getHeight();
    
    // get a reference to the ImageView component that will display the image:
    ImageView img1 = (ImageView)findViewById(R.id.img1);
    
    // scale it to fit the screen, x and y swapped because my image is wider than it is tall
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, y, x, true);
    
    // create a matrix object
    Matrix matrix = new Matrix();
    matrix.postRotate(-90); // anti-clockwise by 90 degrees
    
    // create a new bitmap from the original using the matrix to transform the result
    Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);
    
    // display the rotated bitmap
    img1.setImageBitmap(rotatedBitmap);
    

    检查Create our Android CompassRotating a Bitmap in Android

    【讨论】:

    • 如何使用经纬度旋转图像?
    • 谢谢,但我的问题不同.....我想在 Qibla 指南针应用程序中指向特定位置,在 qibla 指南针应用程序箭头指向 qibla 时,如果我们旋转设备,它仅指向 qibla这就是我需要的
    猜你喜欢
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 2012-12-30
    • 2013-10-16
    • 1970-01-01
    相关资源
    最近更新 更多