iOS Question Rotate image and image sizing

Mark Turney

Active Member
Licensed User
Longtime User
Perhaps I am just dense in the new year. Not sure why ... didn't even drink last nigh :rolleyes:. Anyway, the issue is that I am trying to use the following code to pull an image from SQL, rotate it so that it shows as portrait the way it was taken, and fill the imageview:

B4X:
Buffer = rs.GetBlob("picture")
            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
            returnedPic.Initialize2(InputStream1)
            'flashCards.Bitmap = returnedPic                                        'For testing without rotation
            canvas1.Initialize(flashCards)
            Rect.Initialize(0,0, imgRt, imgBt)
            canvas1.DrawBitmapRotated(returnedPic, Rect, 90)                        'Rotates image after retrieve from SQL
            canvas1.Refresh
            InputStream1.Close

If I use Content Mode of Center, the imageview (flashCards) displays the canvas the correct size of the flashCards imageview dimensions. But, the image itself is cropped ... it's too big and doesn't show all of it.

If I use a Content Mode of Fill. the the imageview (flashCards) displays the canvas too short and wide. But, the image itself is all shown. Like it's compressed.

Any thoughts?

Thanks!
 

Mark Turney

Active Member
Licensed User
Longtime User
I resolved the problem of saving a rotated image to the gallery. I simply had to save the already rotated image directly from the canvas, as opposed to the decoded base64 image from SQL. However, the image as displayed on the canvas in the flashCards imageview is still either: correct sized canvas as the imageview if I use content mode of center (but in this case, the image does not resize itself and is cropped), or incorrectly sized canvas (squished, whereby the image looks "fat") if I use Fill.

If this doesn't make sense, I can grab some screen shots after a couple hours of my "day job" ... lol!

Thanks Erel!
 
Upvote 0

Mark Turney

Active Member
Licensed User
Longtime User
Here's the screenshots:
upload_2015-1-2_8-45-39.png
upload_2015-1-2_8-46-25.png
upload_2015-1-2_8-46-41.png

The Home window is the size I want the canvas to be when displaying the image on the Flashcards page. As you can see in the second image where I have set the content mode to center, the canvas size is correct, but the image is cropped. And in the third image where the content mode is fill, the canvas size and thus image is "off".

I have a feeling it has something to do with the rotation in this code:

B4X:
Buffer = rs.GetBlob("picture")
            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
            returnedPic.Initialize2(InputStream1)
            'flashCards.Bitmap = returnedPic                                        'For testing without rotation
            canvas1.Initialize(flashCards)
            Rect.Initialize(0,0, imgRt, imgBt)
            canvas1.DrawBitmapRotated(returnedPic, Rect, 90)                        'Rotates image after retrieve from SQL
            canvas1.Refresh
            InputStream1.Close

I have two options as I see it: keep center content mode and resize the image. But I'm not quite sure how?!?! Or, correct whatever is "skewing" the canvas.

Thanks again!
 

Attachments

  • upload_2015-1-2_8-46-18.png
    upload_2015-1-2_8-46-18.png
    41.5 KB · Views: 364
Upvote 0

Mark Turney

Active Member
Licensed User
Longtime User
I resolved this and will soon post a tutorial titled "DrawBitmapRotated over ImageView".
 
Last edited:
Upvote 0
Top