Phimageresultisdegradedkey/Phimagefileurlkey Is Not Found

PHImageResultIsDegradedKey/PHImageFileURLKey is not found

1.PHImageResultIsDegradedKey is now being available in latest iOS 13 GM and GM2. So one problem solved.

2.PHImageFileURLKey won't be available in iOS 13 and if you are in so need of fileURL of an image asset and you need it without any PhotoKit's methods callback go for regex in description of asset. It will work.

You can get the description of a PHAssetResource object using +[PHAssetResource assetResourcesForAsset:] , use first object from resulting array and then extract the fileURL from string using regex:

public static func getFileURLFromPHAssetResourceDescription(description: String) -> String? {
let regex = try! NSRegularExpression(pattern: "(?<=fileURL: ).*(?=\\s)")
if let result = regex.firstMatch(in: description, options: [], range: NSRange(location: 0, length: description.count)) {
let url = String(description[Range(result.range, in: description)!])
return url
}
return nil
}

Note: Only available from iOS9

Photos Framework requestImageDataForAsset occasionally fails

You are likely iterating through an array, and memory is not freed timely, you can try the below code. Make sure theData is marked by __block.

@autoreleasepool {
[imageManager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
NSLog(@"requestImageDataForAsset returned info(%@)", info);
theData = [imageData copy];
}];
}

upload picked image in objective-c

You are assigning the picked image to your imageView. So you can access it using the image property of that UIImageView.

You can access like:

- (IBAction)uploadPic:(UIButton *)sender
{
NSData *dataImage = UIImageJPEGRepresentation(self.imageView.image, 1.0f);
// Do your stuff here
}

PHImageManager getting photo incorrectly because of edit from photo library

Okey I find out what happens there.

In PHImageRequestOptions there is an option to choose the unadjusted version of the photo by adding;

requestOptions.version = PHImageRequestOptionsVersionUnadjusted;

With this, I successfully get the Image (however in unadjusted format).

Anyone could find further solution without taking the image adjusted, please comment me.

Cheers.

Xamarin - Is there a similar framework to Photokit (iOS) available for Android, or a good way to get the filestream of all images in the gallery?

You can use ContentResolver in Android .

Add the following permission in Manifest.xml

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

in your DepdencyService

void GetAllImage()
{
Android.Net.Uri imageUri = MediaStore.Images.Media.ExternalContentUri;
var carsor = ContentResolver.Query(imageUri,null, MediaStore.Images.ImageColumns.MimeType + "=? or "+ MediaStore.Images.ImageColumns.MimeType+ "=?",new string[] { "image/jpeg", "image/png" }, MediaStore.Images.ImageColumns.DateModified);

while(carsor.MoveToNext())
{
string path = carsor.GetString(carsor.GetColumnIndex(MediaStore.Images.ImageColumns.Data));
Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
streamArray.Add(stream);
}

}


Related Topics



Leave a reply



Submit