public async void AddBackImage(ContactModel contactItem, RasterImage backImage, Stream imageStream) { string imageFileName = Path.GetFileNameWithoutExtension(contactItem.Picture).Replace("image_", ""); string backImagePath = Path.Combine(HomePage.APP_DIR, $"back_{imageFileName}.jpeg"); if (imageStream != null) { await DependencyService.Get <IPictureSaver>().SaveImage(imageStream, backImagePath, PictureSaveResolution.Medium, false); } else if (backImage != null) { LeadSize size = ImageSizeHelper.GetImageSize(backImage.Width, backImage.Height, PictureSaveResolution.Medium); ResizeInterpolateCommand resizeInterpolateCommand = new ResizeInterpolateCommand(size.Width, size.Height, ResizeInterpolateCommandType.Resample); resizeInterpolateCommand.Run(backImage); using (var codecs = new RasterCodecs()) { codecs.Save(backImage, backImagePath, RasterImageFormat.Jpeg, 0); } } contactItem.BackImage = backImagePath; HomePage.Instance.SaveContactList(); SetBackImage(); }
public async void AddProfileImage(ContactModel contactItem, RasterImage image, Stream imageStream) { string imageFileName = Path.GetFileNameWithoutExtension(contactItem.Picture).Replace("image_", ""); string filePath = Path.Combine(HomePage.PROFILE_PICS_DIR, $"profile_{imageFileName}.jpeg"); if (imageStream != null) { await DependencyService.Get <IPictureSaver>().SaveImage(imageStream, filePath, PictureSaveResolution.Low, false); } else if (image != null) { LeadSize size = ImageSizeHelper.GetImageSize(image.Width, image.Height, PictureSaveResolution.Low); ResizeInterpolateCommand resizeInterpolateCommand = new ResizeInterpolateCommand(size.Width, size.Height, ResizeInterpolateCommandType.Resample); resizeInterpolateCommand.Run(image); using (var codecs = new RasterCodecs()) { codecs.Save(image, filePath, RasterImageFormat.Jpeg, 0); } } contactItem.ProfileImage = filePath; Device.BeginInvokeOnMainThread(() => profileImageView.Source = filePath); HomePage.Instance.SaveContactList(); }