This is what I have so far:
PhotosPicker(selection: $selectedItem, matching: .any(of: [.images, .videos]), photoLibrary: .shared()){
Image(systemName: "camera.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 22)
.foregroundColor(Color("BtnDefaultBG"))
}
.onChange(of: selectedItem) { newItem in
Task {
if let data = try? await newItem?.loadTransferable(type: Data.self) {
uploadData = data
var mimeType = Swime.mimeType(data: uploadData!)!.mime
print(mimeType)
if(mimeType == "image/jpeg"){
image = UIImage(data: uploadData!)!
uploadData = image!.jpegData(compressionQuality: 1)
do {
try await uploadToServer(mime: mimeType)
}
catch {
print(error)
}
}else if(mimeType == "image/gif"){
// get gif duration
image = UIImage(data: uploadData!)! // animation lost
// I need to be able to do something like this: uploadData = image!.gifData()
do {
try await uploadToServer(mime: mimeType)
}
catch {
print(error)
}
}else if(videoTypes.contains(mimeType)){
}else{
showToastFormatNotSupported = true
}
}else{
showToastFormatNotSupported = true
}
}
}
I need the picket GIF to be displayed in Image(uiImage: image!)
without losing it’s animation.
I also need to check the GIF duration.
And I also have the problem when uploading the GIF data to server, then couple milliseconds are missing in the end. I guess it will be solved when I upload the plain GIF instead of the whole data? So something like:
uploadData = image!.gifData()
All the question I’ve seen for this are outdated and for UIKit or just not what I need
Thanks in advance