This is a migrated thread and some comments may be shown as answers.

Open .BMP from bytearray with mvvm

2 Answers 90 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Fredrik
Top achievements
Rank 2
Fredrik asked on 22 Jul 2013, 06:59 AM
Hello i want to load a .bmp image into ImageEditor.
i tryed doing it the way described below, but i get "Object reference not set to an instance of an object"  when trying to initialize the radbitmap with the byte array. Other formats like .jpeg and .png works fine with the same code

<telerik:RadImageEditorUI Image="{Binding Image}" x:Name="ImageEditorUI" >
        private RadBitmap _image = null;
        public RadBitmap Image
        {
            get { return _image; }
            set
            {
                _image = value;
                RaisePropertyChanged();
            }
        }
 
 
private void BuildAttachmentImage(byte[] FileContent)
        {
            try
            {
                MemoryStream data = new MemoryStream(FileContent);
                Image = new RadBitmap(data);
                RaisePropertyChanged("Image");
            }
            catch (Exception ex)
            {
                ShowMessage(MessageSeverity.FatalError, ex.Message, ex.ToString());
            }
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 24 Jul 2013, 03:41 PM
Hello Fredrik,

RadBitmap's constructor which receives as a parameter stream can only initialize a RadBitmap in the formats supported by BitmapImage. That said the exception you are observing is normal.

What I'd suggest is to use the format providers shipped with RadImageEditor to import the image from the stream instead and everything should be working fine.

I hope this helps! Let us know if you have other comments or questions.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Fredrik
Top achievements
Rank 2
answered on 30 Jul 2013, 07:48 AM
thank you, was just what i needed

private void BuildAttachmentImage(byte[] FileContent, string extension)
        {
            try
            {
                MemoryStream data = new MemoryStream(FileContent);
                IImageFormatProvider formatProvider = ImageFormatProviderManager.GetFormatProviderByExtension(extension);
 
                Image = formatProvider.Import(data);
                RaisePropertyChanged("Image");
 
            }
            catch (Exception ex)
            {
                ShowMessage(MessageSeverity.FatalError, ex.Message, ex.ToString());
            }
        }
Tags
ImageEditor
Asked by
Fredrik
Top achievements
Rank 2
Answers by
Petya
Telerik team
Fredrik
Top achievements
Rank 2
Share this question
or