Converting Image to JPEG Byte[] to pass to Web Service

May 13, 2010 at 4:09 PM

Hi,

Thanks for all your hard work with your Image Tools.  I'm trying to convert a UIElement to a byte array that I can pass to a webservice to save the image to a SharePoint Picture Library.  I am struggling with how to use the JpegEncoder to take the Image and convert it to a byte[].

Any help would be greatly appreciated.

Thank you,

John

May 13, 2010 at 8:17 PM

I figured it out:

            ImageTools.Image image = element.ToImage();
            using (MemoryStream stream = new MemoryStream())
            {
                JpegEncoder encoder = new JpegEncoder();
                encoder.Quality = quality;
                encoder.Encode(image, stream);
                stream.Seek(0, SeekOrigin.Begin);
                byte[] binaryData = new Byte[stream.Length];
                long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
                return binaryData;
            }

Nov 29, 2013 at 2:50 AM
Nice work. Can I just copy your smaple code to my .net image converting program with Image Tools, or should I still need some external appliation to activate it?