[英]Convert Java Byte[] to VB.NET MemoryStream
We are developing an Android Application (Java) that reads an image, encode the bytes in base64 to send them over HTTP (via GET) to a WebService written in VB.NET. 我们正在开发一个Android应用程序(Java),它读取一个图像,对base64中的字节进行编码,通过HTTP(通过GET)将它们发送到用VB.NET编写的WebService。
On .NET side, they are using this : 在.NET方面,他们使用这个:
Dim Pix As Image
Pix = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Tree.jpg")
Dim ms As New MemoryStream
Pix.Save(ms, ImageFormat.Jpeg)
Dim ImByte() As Byte = ms.GetBuffer
ms.Close()
Sounds great. 听起来不错。
How can I pass the correct string to them to correctly decode the image from Java encoding (unsigned) to .NET decoding (signed)? 如何将正确的字符串传递给它们以正确解码从Java编码(无符号)到.NET解码(签名)的映像?
Many thanks Nicolas. 非常感谢尼古拉斯。
First mistake: you're using GetBuffer()
which will potentially be too big. 第一个错误:你使用的
GetBuffer()
可能太大了。 Use ToArray()
instead. 请改用
ToArray()
。
On the Java side, just use any Base64 decoder, such as the Apache Commons Codec one . 在Java方面,只需使用任何Base64解码器,例如Apache Commons Codec解码器 。 Don't worry about the signedness of the bytes - Base64 effectively makes that a non-issue for you.
不要担心字节的签名 - Base64有效地使您无需担心。
That's assuming the web service client doesn't perform this automatically for you, of course... if your web service "advertises" a byte array using base64, it may well just be automatic. 这是假设Web服务客户端不会自动为您执行此操作,当然......如果您的Web服务使用base64“通告”一个字节数组,它可能只是自动的。
Side question: why bother loading the image as an image at all? 附带问题:为什么要将图像加载为图像呢? Why not just use:
为什么不使用:
Dim ImByte() As Byte = File.ReadAllBytes("C:\Users\...\Tree.jpg")
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.