- Home
- Forum
- Xamarin.Forms
- Sf ImageEditor iOS saved file path?
Sf ImageEditor iOS saved file path?
How do I get the iOS saved file path of sfimageeditor on Xamarin.forms iOS.
On Xamarin.forms android it has no problem, the "args.Location" return the correct full path to the the image file.
But on Xamarin.forms iOS, the "args.Location" that I got from "Editor_ImageSaved" event is something like "4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001".
On Xamarin.forms android it has no problem, the "args.Location" return the correct full path to the the image file.
But on Xamarin.forms iOS, the "args.Location" that I got from "Editor_ImageSaved" event is something like "4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001".
Which doest not exist as a file. I guess this is some iOS thingy, not a direct file path like on android.
What did this string refer to?
How do I get the direct file path of the saved imaged file?
Thanks♥
SIGN IN To post a reply.
3 Replies
AK
Ashwin Kumaravel
Syncfusion Team
January 24, 2018 06:50 PM UTC
Hi KITTIPAT,
Thanks for using syncfusion products.
Query- How do I get the iOS saved file path of sfimageeditor on Xamarin.forms iOS and I got from "Editor_ImageSaved" event is something like "4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001"
We have validated your query, in iOS we will get only the Image LocalIdentifier. This is the Framework behavior in iOS.We have used PHPhotoLibrary to save an image.Once the Image is saved,we will get the LocalIdentifier of the Image/Asset(4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001).We can load the image from the LocalIdentifier.
Please refer the following link for better understanding
https://developer.apple.com/documentation/photos/phasset/1624732-fetchassetswithlocalidentifiers
Thanks for using syncfusion products.
Query- How do I get the iOS saved file path of sfimageeditor on Xamarin.forms iOS and I got from "Editor_ImageSaved" event is something like "4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001"
We have validated your query, in iOS we will get only the Image LocalIdentifier. This is the Framework behavior in iOS.We have used PHPhotoLibrary to save an image.Once the Image is saved,we will get the LocalIdentifier of the Image/Asset(4E5EDD93-D297-4C28-B554-D1490205A01A/L0/001).We can load the image from the LocalIdentifier.
Please refer the following link for better understanding
https://developer.apple.com/documentation/photos/phasset/1624732-fetchassetswithlocalidentifiers
Please find the code snippet to load the image from the LocalIdentifier
void IImageEditorDependencyService.GetImageFromLocalIdentifier(string path)
{
string[] str = path.Split('/');
PHFetchResult assetResult = PHAsset.FetchAssetsUsingLocalIdentifiers(str, null);
PHAsset asset = assetResult.firstObject as PHAsset;
Stream stream = null;
PHImageManager.DefaultManager.RequestImageData(asset, null, (data, dataUti, orientation, info) =>
{
UIImage newImage = new UIImage(data);
});
}
In the above code snippet path is the LocalIdentifier of the image. We have fetched the path and loaded as UIImage.
Please get back to us if you have any concern
Regards,
Ashwin
FK
Fravius Kalisa
May 8, 2018 12:49 PM UTC
Hello, thanks for this. I am facing same problem. From this: UIImage newImage = new UIImage(data), how do I retrieve newImage path so as to save it somewhere else.
Thanks.
MV
Mohana V
Syncfusion Team
May 9, 2018 07:03 AM UTC
Hi Fravius,
Thanks for contacting syncfusion support.
Query: "How do I retrieve newImage path so as to save it somewhere else?"
In Forms.iOS we can't give any direct path to save the image file due to security reasons rather we can specify any of the predefined folder path which is listed under "Environment.SpecialFolder", to save an image.
You can save the images to the application folder with the Stream obtained from ImageSaving event. The Stream is then converted to image and saved inside the app location.
Thanks for contacting syncfusion support.
Query: "How do I retrieve newImage path so as to save it somewhere else?"
In Forms.iOS we can't give any direct path to save the image file due to security reasons rather we can specify any of the predefined folder path which is listed under "Environment.SpecialFolder", to save an image.
You can save the images to the application folder with the Stream obtained from ImageSaving event. The Stream is then converted to image and saved inside the app location.
Please find below code snippet to save the image to app folder:
Code snippet:
string ISave.Save(Stream stream)
{
byte[] byteArray = null;
//Create Directory inside App Folder
var appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var directoryname = Path.Combine(appdata, "Saved Images");
if (!Directory.Exists(directoryname))
Directory.CreateDirectory(directoryname);
stream.Position = 0;
// Convert Stream to byte[]
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
byteArray = ms.ToArray();
}
string savedPath = System.IO.Path.Combine(directoryname, "edits.jpg");
System.IO.File.WriteAllBytes(savedPath, byteArray);
return savedPath;
}
We have prepared a sample to achieve this requirement. Please find the sample from the below location:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/ImageSavingSample387064064
In the sample, we have used the stream obtained from the ImageSaving event saved as image in the Documents directory of the App. We have also displayed the image saved location as a pop up.
Note: Some of the SpecialFolders are Personal,MyDocuments,MyPictures etc.
Please get back us, if you need any further assistance from our side.
Regards,
Mohana V
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
KT KITTIPAT TATSANAKIT
- Jan 23, 2018 01:25 PM UTC
- May 9, 2018 07:03 AM UTC