public void ConvertBackThrowsNotImplementedException() { var converter = new ByteArrayToImageSourceConverter(); var ex = Record.Exception(() => converter.ConvertBack(null, typeof(byte[]), null, CurrentCulture)); Assert.IsType <NotImplementedException>(ex); }
public void NullValueReturnsNull() { var converter = new ByteArrayToImageSourceConverter(); object value = null; var ex = Record.Exception(() => value = converter.Convert(null, typeof(ImageSource), null, CurrentCulture)); Assert.Null(ex); Assert.Null(value); }
public void ByteArrayToImageSourceConverter() { var byteArray = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; var memoryStream = new MemoryStream(byteArray); var expectedValue = ImageSource.FromStream(() => memoryStream); var byteArrayToImageSourceConverter = new ByteArrayToImageSourceConverter(); var result = byteArrayToImageSourceConverter.Convert(byteArray, typeof(ByteArrayToImageSourceConverter), null, CultureInfo.CurrentCulture); Assert.IsTrue(StreamEquals(GetStreamFromImageSource((ImageSource?)result), memoryStream)); }
public async Task AddImageCommand() { FileData filedata = await CrossFilePicker.Current.PickFile(); //Getting the filename and the data info from the image picked FileName = filedata.FileName; _imageData = filedata.DataArray; //Convert from data info to image ByteArrayToImageSourceConverter converter = new ByteArrayToImageSourceConverter(); //Image that will be displayed ImgSource = converter.Convert(_imageData, null, null, culture: System.Globalization.CultureInfo.CurrentCulture); }
private void GetLayoutTemplates(PaperSize paperSize) { string path = _folderService.GetBookTemplateFolder(paperSize.ToString()); Layouts = new ObservableCollection <BookLayout>(_bookLayoutService.LoadLayoutsFromDirectory(path)); BitmapSource image = new BitmapImage(new Uri("pack://application:,,,/Resources/Img/MemoriesWhite.jpg")); Layouts.Insert(0, new BookLayout { Name = "빈 책", PreviewSource = ByteArrayToImageSourceConverter.SourceToByteArray(image) }); }
public async Task ConvertedImageSourceReturnsSameImage() { var image = GetAvantiPointLogo(); var converter = new ByteArrayToImageSourceConverter(); StreamImageSource imageSource = null; var ex = Record.Exception(() => imageSource = (StreamImageSource)converter.Convert(image, typeof(ImageSource), null, CurrentCulture)); Assert.Null(ex); Assert.NotNull(imageSource); var stream = await imageSource.Stream(CancellationToken.None); var convertedStream = ReadFully(stream); Assert.Equal(image, convertedStream); }
public override void OnDialogOpened(IDialogParameters parameters) { base.OnDialogOpened(parameters); string path = _folderService.GetPageTemplateFolder(parameters.GetValue <PaperSize>("PaperSize").ToString()); Layouts = new ObservableCollection <BookPageLayout>(_bookPageLayoutService.LoadPageLayoutsFromDirectory(path)); BitmapSource image = new BitmapImage(new Uri("pack://application:,,,/Resources/Img/MemoriesWhite.jpg")); Layouts.Insert(0, new BookPageLayout { Name = "빈 페이지", PreviewSource = ByteArrayToImageSourceConverter.SourceToByteArray(image) }); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { ImageCircleRenderer.Init(); //HACK: get iOS to recognize library ByteArrayToImageSourceConverter cn = new ByteArrayToImageSourceConverter(); ImageCircleRenderer.Init(); global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); new SfKanbanRenderer(); return(base.FinishedLaunching(app, options)); }
private void SelectImage(FrameworkElement element) { byte[] source; bool isImage = false; if (element is MMCenterImage image) { isImage = true; source = ByteArrayToImageSourceConverter.SourceToByteArray((BitmapSource)image.ImageSource); } else { source = Background; } _dialogService.ShowSelectImageDialog(new DialogParameters { { ParameterNames.SelectedImage, source } }, (result) => { if (result.Result != ButtonResult.OK) { return; } byte[] selectedImgae = result.Parameters.GetValue <byte[]>(ParameterNames.SelectedImage); if (isImage) { (element as MMCenterImage).ImageSource = (selectedImgae == null) ? null : (BitmapSource) new ImageSourceConverter().ConvertFrom(selectedImgae); } else { Background = selectedImgae; } }); }
public void InvalidConverterValuesReturnsNull(object value) { var byteArrayToImageSourceConverter = new ByteArrayToImageSourceConverter(); Assert.Throws <ArgumentException>(() => byteArrayToImageSourceConverter.Convert(value, typeof(ByteArrayToImageSourceConverter), null, CultureInfo.CurrentCulture)); }
public void SetSourceFromPath(string path) { Preview = path; Source = ByteArrayToImageSourceConverter.SourceToByteArray(new BitmapImage(new Uri(path, UriKind.Relative))); }
/// <summary> /// Extract source from image control /// </summary> /// <param name="image">source image</param> /// <returns></returns> private static byte[] GetSourceFromImage(BitmapSource source) { return(source == null ? null : ByteArrayToImageSourceConverter.SourceToByteArray(source)); }