我正在使用 ELCImagepicker.dll 创建具有多图像选择的画廊。一切正常。
1-我想在用户选择时更改 Tick 的图标。这是非常古老的风格 2- 更改最大选择的验证消息。我想使用“选择”这个词而不是“发送”。
这是媒体服务文件。maxImage
设置最大图像的验证
public class MediaService : IMediaService
{
public async Task OpenGallery(int maxImage)
{
var picker = ELCImagePickerViewController.Create(maxImage);
picker.MaximumImagesCount = maxImage;
var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (topController.PresentedViewController != null)
{
topController = topController.PresentedViewController;
}
topController.PresentViewController(picker, true, null);
List<string> images = new List<string>();
await picker.Completion.ContinueWith(t =>
{
picker.BeginInvokeOnMainThread(() =>
{
//dismiss the picker
picker.DismissViewController(true, null);
if (t.IsCanceled || t.Exception != null)
{
}
else
{
//List<string> images = new List<string>();
var items = t.Result as List<AssetResult>;
foreach (var item in items)
{
var path = Save(item.Image, item.Name);
images.Add(path);
//CleanPath(path);
}
}
});
});
MessagingCenter.Send<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", images);
}
string Save(UIImage image, string name)
{
var documentsDirectory = Environment.GetFolderPath
(Environment.SpecialFolder.Personal);
string jpgFilename = System.IO.Path.Combine(documentsDirectory, name); // hardcoded filename, overwritten each time
NSData imgData = image.AsJPEG();
NSError err = null;
if (imgData.Save(jpgFilename, false, out err))
{
return jpgFilename;
}
else
{
Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription);
return null;
}
}
void IMediaService.ClearFiles(List<string> filePaths)
{
var documentsDirectory = Environment.GetFolderPath
(Environment.SpecialFolder.Personal);
if (Directory.Exists(documentsDirectory))
{
foreach (var p in filePaths)
{
File.Delete(p);
}
}
}
}