title: Constantly refreshing UIImage
body: <p>I am trying to send an image to an iOS app from a Java client. I need to send the image as fast as possible to get high fps. I tried using sockets but it was too slow, so now I am uploading to a server from the client and downloading it with the app. This works when using a java receiver, but not on the app. When viewed on the app the image just comes up black, because the image is being saved again and again. In java the image refreshes and you can see the frames, but in iOS its just always black. Is there anyway I can fix this? Or do I need to find a better way to transfer the image? Thanks!</p>
  
  <p>My Upload Code:</p>
  
  <pre><code>public static BufferedImage resize(BufferedImage img, int newW, int newH) {
      int w = img.getWidth();
      int h = img.getHeight();
      BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
      Graphics2D g = dimg.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
      g.dispose();
      return dimg;
  }
  
  public void uploadToServer() {
  
      String server = "ip";
      int port = 21;
      String user = "user";
      String pass = "pass";
  
      FTPClient ftpClient = new FTPClient();
      try {
  
          ftpClient.connect(server, port);
          ftpClient.login(user, pass);
          ftpClient.enterLocalPassiveMode();
  
          ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
  
          ByteArrayOutputStream os = new ByteArrayOutputStream();
  
          int w = 765;
          int h = 503;
          double d = .75;
  
          ImageIO.write(
                  resize(client.methods.getClientImage(), (int) (w * d),
                          (int) (h * d)), "JPG", os);
  
          InputStream inputStream = new ByteArrayInputStream(os.toByteArray());
  
          String secondRemoteFile = "public_html/iRS/client_img.jpg";
  
          // System.out.println("Start uploading file");
          OutputStream outputStream = ftpClient
                  .storeFileStream(secondRemoteFile);
  
          byte[] bytesIn = new byte[4096];
          int read = 0;
  
          while ((read = inputStream.read(bytesIn)) != -1) {
              outputStream.write(bytesIn, 0, read);
          }
  
          inputStream.close();
          outputStream.close();
          ftpClient.completePendingCommand();
  
      } catch (IOException ex) {
          System.out.println("Error: " + ex.getMessage());
          ex.printStackTrace();
      } finally {
          try {
              if (ftpClient.isConnected()) {
                  ftpClient.logout();
                  ftpClient.disconnect();
                  Tools.log("Disconnected");
              }
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Download code:</p>
  
  <pre><code>- (void) refreshImage {
          client.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL   URLWithString:@"url"]]]; ;
  }
  </code></pre>