1

i have images on a webserver and I convert they in Base64 to receive it on a .Net application. I use this code:

$imagedata = file_get_contents($local_uri);
$d = base64_encode($imagedata);

It works perfekt.

Now i had the idea to resize the images to save time for transmission. So I resize the images with a simple PHP-Framework from http://deruwe.de/vorschaubilder-einfach-mit-php-realisieren-teil-2.html

On behind it use ImageJPEG to "return" or create the edited image. On an other post here i read that if you want to use ImageJPEG and translate it on Base64 you have to use this code:

ob_start();
$thumbnail->output(false, false);
$p = ob_get_contents();
ob_end_clean();
$d = base64_encode($p);

The "new" Base64 code seems legit, because if I try to illustrate it with http://www.freeformatter.com/base64-encoder.html, I got a legit image.

BUT due an unknown reason my .Net application will throw an System.NotSupportedException (No imaging component suitable to complete this operation was found.) and don't like the "new" one.

This is my .Net function to convert Base64 String in BitmapImage:

public static BitmapImage getImage(String s)
    {
        byte[] binaryData = Convert.FromBase64String(s);
        BitmapImage bi = new BitmapImage();
        bi.BeginInit();
        bi.StreamSource = new MemoryStream(binaryData);
        bi.EndInit();
        return bi;
    }

Any idea whats gone wrong or how to fix it?

Denis
  • 439
  • 4
  • 17
  • Does `String s` start with `data:image/png;base64,`, if so try dropping that off. .NET is expecting just the data without that header, see [this](http://stackoverflow.com/a/5400225/1124565) answer, they don't have the header when converting – amura.cxg Sep 19 '15 at 03:04
  • I found out, that some image was corrupted. .NET can handle both variants - with and without header. – Denis Sep 21 '15 at 13:59

0 Answers0