Im building a C#, WPF and Android application, mostly for training, but either way, the issue that I have is the follow:
When I execute the followed code WPF app, it saves the desire file from the disk to the desktop, but the problem comes when I try to do the same from the Android application, I do get connected to Console application, but the byte[]
apparently are not the same format, maybe I miss something, or I'm going something wrong.
Convert Image to byte array function: C#
private static byte[] ImageToByteArraybyMemoryStream(Image image) {
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
Save Image to Disk method C#
public static void ByteArrayToImageFilebyMemoryStream(byte[] imageByte) {
try {
MemoryStream ms = new MemoryStream(imageByte);
Image image = Image.FromStream(ms);
image.Save(@"C:\Users\jycr753\Desktop\imageTest1.png");
}
}
Convert to byte[]
and send from Android Application.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapImage.compress(Bitmap.CompressFormat.PNG, 70, stream);
byteArray = stream.toByteArray();
File fl = new File( imagePath);
FileInputStream fi = new FileInputStream( fl );
BufferedInputStream bi = new BufferedInputStream( fi );
bi.read( byteArray, 0, byteArray.length );
OutputStream outs = sock.getOutputStream();
outs.write( byteArray, 0, byteArray.length );
outs.flush();
Image from Console Application
Debugger in Save file method screen shot
Manifest Permitions
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
byte code
Is there any issue if the C# application expect a ASCII
encoding?
Any help of point me in the right direction it will be great, if there is the need to put more code, just ask :)
thanks community..