Delphi 到 Java 代码的转换
我怎样才能将用Delphi编写的特定代码转换为JAVA
try
LLine := TMemoryStream.Create;
IdTCPClient1.IOHandler.WriteLn('atext');
IdTCPClient1.IOHandler.ReadStream(LLine, -1);
LLine.Position := 0;
LLine.Read(intval, 4); //the server is sending memstream as integer + ajpeg image
Image1.Picture.Graphic.LoadFromStream(LLine);
finally
//free
end;
上面的代码与Delphi完美配合,但现在我也想创建一个java客户端,但我自己的转换给了我错误(java)
Image image = null ;
Socket socket = new Socket(someIP, myport);
我的转换是
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String string = "atext\n";
byte buffer[] = string.getBytes();
out.write(buffer);
in.skip(4); // i don't want the integer
image = ImageIO.read(in);
服务器正在获取文本 atext 完美,但我的 java 客户端遇到问题,图像始终显示空值(我分配了一个断点并检查了它);
how can i convert the specific code written in Delphi to JAVA
try
LLine := TMemoryStream.Create;
IdTCPClient1.IOHandler.WriteLn('atext');
IdTCPClient1.IOHandler.ReadStream(LLine, -1);
LLine.Position := 0;
LLine.Read(intval, 4); //the server is sending memstream as integer + ajpeg image
Image1.Picture.Graphic.LoadFromStream(LLine);
finally
//free
end;
the above code works perfectly with Delphi , but now i want to create a java client too , but my own conversion is giving me error(java)
Image image = null ;
Socket socket = new Socket(someIP, myport);
My conversion is
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
String string = "atext\n";
byte buffer[] = string.getBytes();
out.write(buffer);
in.skip(4); // i don't want the integer
image = ImageIO.read(in);
the server is getting the text atext perfectly , but my java client is having a problem always image is showing a null value (i assigned a breakpoint and checked it );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ImageIO.read(InputStream input) 文档说:
所以在这种情况下 null 值似乎是正常的。您是否检查过匹配的 ImageReader 是否已注册? (例如,通过加载现有的有效参考图像文件)
The ImageIO.read(InputStream input) documentation says:
So the null value seems to be normal in this case. Have you checked that a matching ImageReader is registered? (For example by loading an existing, valid reference image file)