Search code examples
androidandroid-canvas

SurfaceView, draw image and reduce size, rotate image


I wan to draw a image (get from camera) on surfaceview. After drawing the image i want to reduce the size of the image, change the image location on surface view with touch. rotate the image. currently i draw the image on surface view but how the remaining task is not done. Please some body help me.

Thanks


Solution

  • public void drawImage(Canvas canvas, Bitmap bitmap, int x, int y, int rotationAngle, float scalingfactor){
            Matrix matrix = new Matrix();
            matrix.postRotate(rotationAngle, bitmap.getWidth()/2, bitmap.getHeight()/2);
            matrix.postScale(scalingfactor, scalingfactor, bitmap.getWidth()/2, bitmap.getHeight()/2);
            matrix.postTranslate(x, y);
            canvas.drawBitmap(bitmap, matrix, null);
        }
    

    Use above code to rotate and scaling image in surfaceview. if scalingfactor 1.0f means, image size will be same. If you want to reduce the size use like 0.5f. rotationAngle is 0 to 360