Silverlight SaveAsString and BitmapImage

Discussions about GdPicture.NET usage in non managed applications built in vb6, Delphi, vfp, MFC c++ etc...
Post Reply
EMDLG71
Posts: 2
Joined: Mon Jul 08, 2013 12:53 pm

Silverlight SaveAsString and BitmapImage

Post by EMDLG71 » Mon Jul 08, 2013 1:24 pm

Dear Sir,
I am using gdpicture dot net 9 inside a silverlight control.
I am trying to use the string data obtained from the SaveAsString function into a Image control using the following code:

...

Code: Select all

                   string MS;

                    MS=oGdPictureImaging.SaveAsString(ImageID, 4, 0);
                    UTF8Encoding unen = new UTF8Encoding();
                    byte[] bArray=unen.GetBytes(MS);
                  
                    using (Stream s = GenerateStreamFromString(bArray))
                    {
                        s.Seek(0, SeekOrigin.Begin);
                        BitmapImage b = new BitmapImage();

                        b.SetSource(s);
                        PagePreview.Source = b;

                    }

public Stream GenerateStreamFromString(byte[] s)
        {
            MemoryStream stream = new MemoryStream();
            for (int i = 0; i < s.Length; i++)
            {
                stream.WriteByte(s[i]);
            }
          
            stream.Position = 0;
            return stream;
        }
No errors are generated but no image is created
I tried tu use the Unicode encoding as well with the same result

Thank you in advance

User avatar
Loïc
Site Admin
Posts: 5526
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Silverlight SaveAsString and BitmapImage

Post by Loïc » Tue Jul 23, 2013 1:05 pm

Hello,

First you should use the SaveAsByteArray() method since you are trying to obtain data stored in this format.

That said, the string data returned by GdPicture is encoded with Codepage Windows-1252.

So I give you compliant code in order to do conversion from / to array of bytes:

Code: Select all

        public static byte[] GetBytes(string data)
        {
            return Encoding.GetEncoding(1252).GetBytes(data);
        }

        public static byte[] GetBytes(string data, int index, int count)
        {
            byte[] b = new byte[count];
            Encoding.GetEncoding(1252).GetBytes(data, index, count,b, 0);
            return b;
        }
Hope this helps!

With best regards,

Loïc

EMDLG71
Posts: 2
Joined: Mon Jul 08, 2013 12:53 pm

Re: Silverlight SaveAsString and BitmapImage

Post by EMDLG71 » Tue Jul 23, 2013 3:42 pm

Many Thanks

Emilio

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest