Delphi 到 Java 代码的转换

发布于 2025-01-04 13:05:22 字数 940 浏览 1 评论 0原文

我怎样才能将用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很快妥协 2025-01-11 13:05:22

ImageIO.read(InputStream input) 文档说:

如果没有注册的 ImageReader 声称能够读取结果
流,返回null。

所以在这种情况下 null 值似乎是正常的。您是否检查过匹配的 ImageReader 是否已注册? (例如,通过加载现有的有效参考图像文件)

The ImageIO.read(InputStream input) documentation says:

If no registered ImageReader claims to be able to read the resulting
stream, null is returned.

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文