Hi alessandrocaliaro,
Welcome to our Microsoft Q&A platform!
To save the image as file, you can create an interface as follows and implement it on both Android and iOS.
public interface ISaveService
{
void SaveFile(string fileName, byte[] data);
}
Android:
[assembly: Xamarin.Forms.Dependency(typeof(SaveService))]
namespace cameraviewDemo.Droid
{
public class SaveService: ISaveService
{
void ISaveService.SaveFile(string fileName, byte[] data)
{
string picPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryPictures);
string filePath = Path.Combine(picPath, fileName);
File.WriteAllBytes(filePath, data);
}
}
}
iOS:
[assembly: Xamarin.Forms.Dependency(typeof(SaveService))]
namespace cameraviewDemo.iOS
{
class SaveService: ISaveService
{
void ISaveService.SaveFile(string fileName, byte[] data)
{
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine(documents, fileName);
File.WriteAllBytes(filename, data);
}
}
}
xaml.cs:
private void cameraView_MediaCaptured(object sender, Xamarin.CommunityToolkit.UI.Views.MediaCapturedEventArgs e)
{
byte[] image = e.ImageData;
DependencyService.Get<ISaveService>().wirteFile("test.jpg", image);
}
Here are some related links you can refer to.
How to write a file to a Internal Storage in xamarin forms which can be found by the user
File system access in Xamarin.iOS
As to set the resolution, you can try to convert the e.ImageData to Bitmap and try method Bitmap.SetResolution(Single, Single) Method and Bitmap.CreateBitmap Method.
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.