iOS Question ALAssetLibrary: read bytes from an asset

wl

Well-Known Member
Licensed User
Hi,

I'm using the ALAssetLibrary to loop though all photo's on my iOS device.
I just want to upload all photos AND videos using HTTP(s), so I need the library to return the videos as well.

This will probably be easy: however I need to get a byte stream (with the photo or video), which should be able to obtain with

ALAssetRepresentation -> getBytes (see: https://developer.apple.com/documentation/assetslibrary/alassetrepresentation)


B4X:
func getBytes(_ buffer: UnsafeMutablePointer<UInt8>!,
   fromOffset offset: Int64,
       length: Int,
        error: NSErrorPointer) -> Int
but I have no clue on how to include the objective c code for this call and return a byte array to B4I code.

The current ALAsset library code assumes an Image to be returned to B4I code:


B4X:
-(UIImage*)im: (ALAsset *)asset
{ ALAssetRepresentation *defaultRep = [asset defaultRepresentation];
  UIImage *_image = [UIImage imageWithCGImage:[defaultRep fullScreenImage] scale:[defaultRep scale] orientation:0];
  return _image;
}
But how should I modify this code to return the byte array ?

Thanks !
 
Last edited:
Top