Rotate a saved bitmap in android

后端 未结 5 1008
终归单人心
终归单人心 2020-12-05 12:11

I am saving an image from the camera that was in landscape mode. so it gets saved in landscape mode and then i apply an overlay onto it that too is in landscape mode. I want

5条回答
  •  难免孤独
    2020-12-05 12:53

    void rotate(float x)
        {
            Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.tedd);
    
            int width = bitmapOrg.getWidth();
    
            int height = bitmapOrg.getHeight();
    
    
            int newWidth = 200;
    
            int newHeight  = 200;
    
            // calculate the scale - in this case = 0.4f
    
             float scaleWidth = ((float) newWidth) / width;
    
             float scaleHeight = ((float) newHeight) / height;
    
             Matrix matrix = new Matrix();
    
             matrix.postScale(scaleWidth, scaleHeight);
             matrix.postRotate(x);
    
             Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,width, height, matrix, true);
    
             iv.setScaleType(ScaleType.CENTER);
             iv.setImageBitmap(resizedBitmap);
        }
    

提交回复
热议问题