This project is read-only.

decoding binay data does not work

May 31, 2011 at 10:51 AM

in using imagetools for decoding binary data and transform to image type (in extended image) has problem for me , it doesn't work and finally the extendedImage display nothing !!!

my code is:

Decoders.AddDecoder<BmpDecoder>();

 Decoders.AddDecoder<PngDecoder>();

 Decoders.AddDecoder<JpegDecoder>();

 Decoders.AddDecoder<GifDecoder>();

     ImageTools.ExtendedImage eximage = new ImageTools.ExtendedImage();

   MemoryStream  ms = new MemoryStream(binaryData, 0, binaryData.Length, false);

     ms.Seek(0, SeekOrigin.Begin);

    System.Collections.ObjectModel.ReadOnlyCollection<IImageDecoder> lst =     Decoders.GetAvailableDecoders();

   foreach (var item in lst)

   {

     if (item.GetType() == typeof(GifDecoder))

       {

         ((GifDecoder)item).Decode(eximage, ms);

 

         BitmapImage bimage = new BitmapImage(eximage.UriSource);

         WriteableBitmap b = new WriteableBitmap(bimage.PixelWidth, bimage.PixelHeight);

         img.Source = b;

       }

   }

plz help me

 

 

 

 

 



May 31, 2011 at 7:51 PM
This code makes no sense. The UriSource property is only used to load an
extended image from a web source.

To load an image just use this approach:

ExtendedImage image = new ExtendedImage();

image.LoadingCompleted += image_loadingCompleted;
image.SetSource(ms);

private void image_LoadingCompleted(...)
{
Dispatcher.BeginInvoke(() =>
{
var bitmap = image.ToBitmap(); // Extension method in
ImageTools.Utils

myImage.Source = bitmap;
});
}
See more here: http://imagetools.codeplex.com/documentation

you can also use the AnimatedImage control:

<it:AnimatedImage x:Name="AnimatedImage" />

ExtendedImage image = new ExtendedImage();
image.SetSource(ms);

AnimatedImage.Source = image;

or you work with AnimatedImage and ImageConverter and binding
Jun 1, 2011 at 7:27 AM

tnx for your help. but i set imagetools.utils.dll to the list of references , but it doesn't recogonized .

then i can't use "image.tobitmap();"

 another point:

in:

void im_LoadingCompleted(object sender, EventArgs e)

{

   ImageTools.ExtendedImage ex = new ImageTools.ExtendedImage();

   Dispatcher.BeginInvoke(() =>

   {

     ex = (ImageTools.ExtendedImage)sender; 

   });

}

ex is image 0x0 and ex.pixels=null ,

why?

 





Sep 12, 2011 at 4:26 PM
malignate88 wrote:
This code makes no sense. The UriSource property is only used to load an
extended image from a web source.

To load an image just use this approach:

ExtendedImage image = new ExtendedImage();

image.LoadingCompleted += image_loadingCompleted;
image.SetSource(ms);

Is there a way to load an image synchronously? Is there any reason for the ExtendedImage.Load method to be private?

Sep 12, 2011 at 4:34 PM
skalkin wrote:

Is there a way to load an image synchronously? Is there any reason for the ExtendedImage.Load method to be private?

Ah I see, we'll simply have to use the corresponding decoder:

using (var stream = ...)
{
   var image = new ExtendedImage();
   new PngDecoder().Decode(image, stream);
   return image.ToBitmap();
}
Sep 12, 2011 at 4:39 PM
Yes, this is a solution.

There are 2 reasons why there is not normal interface:

1. One goal was to have a similar api like the normal image class.

2. Loading an image can be slow.

Sebastian

Am 12.09.2011 17:34, schrieb skalkin:

From: skalkin

skalkin wrote:

Is there a way to load an image synchronously? Is there any reason for the ExtendedImage.Load method to be private?

Ah I see, we'll simply have to use the corresponding decoder:

using (var stream = ...)
{
   var image = new ExtendedImage();
   new PngDecoder().Decode(image, stream);
   return image.ToBitmap();
}

Sep 12, 2011 at 6:48 PM
2. Loading an image can be slow.

Thanks for the answer!

Well. my code already executes in another thread, so loading it asynchronously makes no sense :) Personally, I would prefer to have both methods available, but obviously it does not matter much since there is a way around it.