0

I have a java server and a c# client.

I want to read an .png file on the server, convert it to an byte[], send it through the socket and then convert it back to an imagesource.

This is the java server to convert the image to a byte array:

BufferedImage originalImage = ImageIO.read(new File(ImageName));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( originalImage, "png", baos );
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
return imageInByte; 

This is the C# client to convert the byte Array to an Image/Imagesource:

BitmapImage biImg = new BitmapImage();
MemoryStream ms = new MemoryStream(imageData);
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.EndInit();

ImageSource imgSrc = biImg as ImageSource;
return imgSrc;

The problem is that i get a NotSupportetException on biImg.EndInit();

  • Pls show the logs. – KayV Apr 09 '16 at 08:42
  • Convert byte[] to base64 – Prabhat Sinha Apr 09 '16 at 08:46
  • Looks as it should work, Are you sure the buffer is transported completely? Check the length on both server and client side. As a note, you don't need to cast `imgSrc = biImg as ImageSource`. You could instead directly return `biImg`, because it already *is an* ImageSource by inheritance. – Clemens Apr 09 '16 at 09:24
  • why don't you simply transfer the original png? – wero Apr 09 '16 at 10:01
  • I found the problem, its was acually a problem with the String to byte[] convertation, i missed that java uses signed bytes as default and c# uses unsigned –  Apr 10 '16 at 14:30

0 Answers0