SurfaceView, draw image and reduce size, rotate image

≯℡__Kan透↙ 提交于 2020-01-14 07:00:47

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/21234002/surfaceview-draw-image-and-reduce-size-rotate-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!