如何将 FFImageLoading DownSample 应用于我具有 DataArray 的图像?
How can I apply FFImageLoading DownSample to an image which I have its DataArray?
我正在使用 FFImageLoading crop/rotate 使用 Xamarin.Plugin.FilePicker(版本 1.1.0)选取的图像。此选择器仅允许获取 DataArray 和文件名,但不提供文件路径。我在互联网上看到一些线程在谈论 .FilePath 属性 但它并没有出现在我身上。
所以我得到了文件:
FileData filedata = await CrossFilePicker.Current.PickFile();
向下采样:
var a = await ImageService.Instance.LoadBase64String(Convert.ToBase64String(filedata.DataArray)).DownSample(300).AsJPGStreamAsync();
然后,我从流转换为图像源:
ImageSource imagem = ImageSource.FromStream(() =>a);
但我总是得到:
Image loading failed: /9j/4AAQSkZJRgABAQAAAQABAAD/7QCEUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAGgcAmcAFC11eGVqcnZjX1pkR09yNUN3cWRZHAIoAEpGQk1EMGYwMDA3NzAwMTAwMDBlMDAzMDAwMGE3MDkwMDAwYjAwYTAwMDBhMjBiMDAwMGUxMTQwMDAwZWYxYTAwMDA4NDFjMDAwMP/bAEMACwgICggHCwoJCg0MCw0RHBIRDw8RIhkaFBwpJCsqKCQnJy0yQDctMD0wJyc4TDk9Q0VISUgrNk9VTkZUQEdIRf/bAEMBDA0NEQ8RIRISIUUuJy5FRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRf/CABEIAKQA3AMBIgACEQEDEQH/xAAbAAEAAwEBAQEAAAAAAAAAAAAABAUGAwcBAv/EABoBAQADAQEBAAAAAAAAAAAAAAADBAUBAgb/2gAMAwEAAhADEAAAANOKdAAfh39o0p34HkAABx5fYLMKVa1EFieL2cAAAAAhzIsNmwrJ03C2KSbxi7OVYI/3iRw/EiGb88/32535N+QcrRkUN1nb1e/G1hgAAAAI0nhTufufzi4ux1m/PsXsPHQAAKPjoaDTqWI28IAACNI2dHNYqXOLHFOhzYdWe6HzO8B8K/1ywV9h3n35m5E/i9FWX5RXt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HhM0NTYpKi8PFAY4KjwvL/2gAIAQEACD8B/wChlcIo3moT5pHuZ1ux+G6m0YjW3H1zbBT+jc+y+nqlUvK3
FFImageLoading.DownloadAggregateException: One or more errors occurred. (An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.)
我知道我在这次转换中做错了,但还找不到错误。
如果你想从系统相册中选择照片,你可以安装nuget插件Xam.Plugin.Media。
用法
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
var file = await CrossMedia.Current.PickPhotoAsync();
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
有关详细信息,您可以查看 https://github.com/jamesmontemagno/MediaPlugin .
我正在使用 FFImageLoading crop/rotate 使用 Xamarin.Plugin.FilePicker(版本 1.1.0)选取的图像。此选择器仅允许获取 DataArray 和文件名,但不提供文件路径。我在互联网上看到一些线程在谈论 .FilePath 属性 但它并没有出现在我身上。
所以我得到了文件:
FileData filedata = await CrossFilePicker.Current.PickFile();
向下采样:
var a = await ImageService.Instance.LoadBase64String(Convert.ToBase64String(filedata.DataArray)).DownSample(300).AsJPGStreamAsync();
然后,我从流转换为图像源:
ImageSource imagem = ImageSource.FromStream(() =>a);
但我总是得到:
Image loading failed: /9j/4AAQSkZJRgABAQAAAQABAAD/7QCEUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAGgcAmcAFC11eGVqcnZjX1pkR09yNUN3cWRZHAIoAEpGQk1EMGYwMDA3NzAwMTAwMDBlMDAzMDAwMGE3MDkwMDAwYjAwYTAwMDBhMjBiMDAwMGUxMTQwMDAwZWYxYTAwMDA4NDFjMDAwMP/bAEMACwgICggHCwoJCg0MCw0RHBIRDw8RIhkaFBwpJCsqKCQnJy0yQDctMD0wJyc4TDk9Q0VISUgrNk9VTkZUQEdIRf/bAEMBDA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Mrorr/iB32O3Xyro3i79/lsdR+WSgpjybr7SOtI/LyDdSb1nBpDc/mft6//xAAjEQEAAQQCAwACAwAAAAAAAAABAgADBBESIBAhMDFBEzIz/9oACAEDAQE/APKJ6TXWzjyutZOOW4Cd8Y3cBqVqNwRKu4soOg2VHDuyowH9tGCkjbQEACsr3bQ74X+lexdFAh765IRtqdWyfppglYg/ymvMpETbUZEjZXM5cfF6I20e9tIS5VCZI2eJgiNFyFs1um9EVCnJk/gqV6b6WuBXEqYRNh1jJi7KclTQUzk/l73ZbdfVdG6Xbt+tx1H6htCpQhCCv1tupDWXdOPH7S/s+f/EAEEQAAIBAgMDBwoEBQMFAQAAAAECAwARBBIhMUFREBMgIjJhcQUUIzBCUoGRocFysdHhM0NTYpKi8PFAY4KjwvL/2gAIAQEACD8B/wChlcIo3moT5pHuZ1ux+G6m0YjW3H1zbBT+jc+y+nqlUvK3
FFImageLoading.DownloadAggregateException: One or more errors occurred. (An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.)
我知道我在这次转换中做错了,但还找不到错误。
如果你想从系统相册中选择照片,你可以安装nuget插件Xam.Plugin.Media。
用法
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
var file = await CrossMedia.Current.PickPhotoAsync();
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
return stream;
});
有关详细信息,您可以查看 https://github.com/jamesmontemagno/MediaPlugin .