Hello everyone, I am trying to get image height an...
# multiplatform
d
Hello everyone, I am trying to get image height and width that is selected from gallery. Works fine on Android but in
iOSMain
module there are issues. Size of the selected image is returned as
0
for height and
2.233E-321
for width. Code in 🧵
Copy code
object :
            NSObject(),
            UIImagePickerControllerDelegateProtocol,
            UINavigationControllerDelegateProtocol {
            override fun imagePickerController(
                picker: UIImagePickerController,
                didFinishPickingMediaWithInfo: Map<Any?, *>,
            ) {
                val image =
                    didFinishPickingMediaWithInfo.getValue(
                        UIImagePickerControllerEditedImage,
                    ) as? UIImage ?: didFinishPickingMediaWithInfo.getValue(
                        UIImagePickerControllerOriginalImage,
                    ) as? UIImage
                val imageAsNsData = image?.let { UIImagePNGRepresentation(it) }

                imageAsNsData?.let { scopedImageAsNsData ->

                    image?.let { scopedImage ->
                        val size: CGSize = scopedImage.size.useContents { this }
                        Logger.e("00x99 $size")
                        Logger.e("00x99 h: ${size.height}")
                        Logger.e("00x99 w: ${size.width}")

                        continuation?.resume(
                            GalleryManager.DataWithByteArray(
                                data = Data(scopedImageAsNsData),
                                byteArray = scopedImageAsNsData.toByteArrayOrNull(),
                                ratio = (size.height/size.width).toFloat(),
                            ),
                        )
                    }
                }
            }
        }
p
I'd suggest reading the UIKit UIImage docs: https://developer.apple.com/documentation/uikit/uiimage
I don't have the answer, but maybe it' resizable?
d
Issue was in unpacking a
CValue
scopedImage.size.useContents
It works like this
Copy code
val height = scopedImage.size.useContents { this.height }

val width = scopedImage.size.useContents { this.width }
p
Oh fascinating! 🙂 Thanks for sharing!
😀 1