Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Sending BufferedImage thought a socket

Sending BufferedImage thought a socket

Scheduled Pinned Locked Moved Java
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    Can you send a BufferedImage thought a socket by changing it somehow because it is not Serializable, and then on client side using WritableImage to show it inside a ImageView? I am not trying to send an image file but a screenshot made using the following code which I can in the end use it inside ImageView:

    Robot robot = new Robot();
    BufferedImage imageB = robot.createScreenCapture(screenRectangle);
    WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
    ImageView.setImage(imageW);

    J L J 3 Replies Last reply
    0
    • V Valentinor

      Can you send a BufferedImage thought a socket by changing it somehow because it is not Serializable, and then on client side using WritableImage to show it inside a ImageView? I am not trying to send an image file but a screenshot made using the following code which I can in the end use it inside ImageView:

      Robot robot = new Robot();
      BufferedImage imageB = robot.createScreenCapture(screenRectangle);
      WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
      ImageView.setImage(imageW);

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Valentinor wrote:

      Can you send a BufferedImage thought a socket

      No. That class has a specific purpose and what you are doing has nothing to do with that. The class is used to create (and manipulate) an image. The image, not the class is what you will be sending. And as a suggestion if you have never used sockets before then I suggest that you experiment with something besides an image for the first time. Like a simple string.

      V 1 Reply Last reply
      0
      • J jschell

        Valentinor wrote:

        Can you send a BufferedImage thought a socket

        No. That class has a specific purpose and what you are doing has nothing to do with that. The class is used to create (and manipulate) an image. The image, not the class is what you will be sending. And as a suggestion if you have never used sockets before then I suggest that you experiment with something besides an image for the first time. Like a simple string.

        V Offline
        V Offline
        Valentinor
        wrote on last edited by
        #3

        jschell wrote:

        And as a suggestion if you have never used sockets before then I suggest that you experiment with something besides an image for the first time. Like a simple string.

        What is with that suggestion and the relation with what I asked?

        jschell wrote:

        That class has a specific purpose and what you are doing has nothing to do with that.

        I did said the following, I wasn't trying to send it straight, because I knew you can't...

        by changing it somehow because it is not Serializable

        Your comment wasn't useful in the least, it was actually the opposite, it didn't contained anything useful, only a comment to try and look smart and make the other person feel stupid. Nowhere did I said I didn't worked with sockets before, yet you added that last part... You should have left it at "No." and it would have been better, and yet still wrong because you can do something there and change it into bytes and you can still send it, not that is fast, but you can do it. And why didn't you quoted the whole think I said and stopped at that? It's like those manipulations where you get only that you need, not the whole truth. Yeah this is a harsh reply but in the future a more constructive answer is better if not none at all is even better, we want to learn from one another not to just make ourself look smart and not truly help other, or help them with a riddle that it is going to take them even farther from the solution.

        J 1 Reply Last reply
        0
        • V Valentinor

          Can you send a BufferedImage thought a socket by changing it somehow because it is not Serializable, and then on client side using WritableImage to show it inside a ImageView? I am not trying to send an image file but a screenshot made using the following code which I can in the end use it inside ImageView:

          Robot robot = new Robot();
          BufferedImage imageB = robot.createScreenCapture(screenRectangle);
          WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
          ImageView.setImage(imageW);

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Both BufferedImage and WriteableImage utilize (internal) pixel arrays. You "unload" the BufferedImage to a pixel array, transmit it as a stream, then load it into the WriteableImage. There are no explicit "serialize / deserialize" methods; you do it yourself. The "interface" is pixel arrays (in one form or another); that's what you have to remember.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          1 Reply Last reply
          0
          • V Valentinor

            Can you send a BufferedImage thought a socket by changing it somehow because it is not Serializable, and then on client side using WritableImage to show it inside a ImageView? I am not trying to send an image file but a screenshot made using the following code which I can in the end use it inside ImageView:

            Robot robot = new Robot();
            BufferedImage imageB = robot.createScreenCapture(screenRectangle);
            WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
            ImageView.setImage(imageW);

            J Offline
            J Offline
            Joop Eggen 2021
            wrote on last edited by
            #5

            BufferedImage already "unpacked" an image for display/usage usage: the raster of pixels, the color model and such. The only simple serialization is to write the image to some buffer/file, and send those (generally much smaller and faster) bytes. To stress the point: serializing for every image type, indexed color or not, packed RGB and so on, is some effort, requiring some unit tests checking internals of BufferedImage.

            1 Reply Last reply
            0
            • V Valentinor

              jschell wrote:

              And as a suggestion if you have never used sockets before then I suggest that you experiment with something besides an image for the first time. Like a simple string.

              What is with that suggestion and the relation with what I asked?

              jschell wrote:

              That class has a specific purpose and what you are doing has nothing to do with that.

              I did said the following, I wasn't trying to send it straight, because I knew you can't...

              by changing it somehow because it is not Serializable

              Your comment wasn't useful in the least, it was actually the opposite, it didn't contained anything useful, only a comment to try and look smart and make the other person feel stupid. Nowhere did I said I didn't worked with sockets before, yet you added that last part... You should have left it at "No." and it would have been better, and yet still wrong because you can do something there and change it into bytes and you can still send it, not that is fast, but you can do it. And why didn't you quoted the whole think I said and stopped at that? It's like those manipulations where you get only that you need, not the whole truth. Yeah this is a harsh reply but in the future a more constructive answer is better if not none at all is even better, we want to learn from one another not to just make ourself look smart and not truly help other, or help them with a riddle that it is going to take them even farther from the solution.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              Valentinor wrote:

              Your comment wasn't useful in the least, it was actually the opposite,

              You specifically said the following "Can you send a BufferedImage thought a socket by changing it somehow because it is not Serializable," Questions like this have been asked for decades and answered by me when the person doesn't actually understand what a socket is doing. Note that I am not saying that someone hasn't used a socket but rather than they do not know what it is doing. If you had said "how do I send an image" then that would have been different. But you specifically mentioned that class and that it is Serializable. So I answered that specific question.

              Valentinor wrote:

              and you can still send it, not that is fast,

              I didn't say anything at all about performance.

              Valentinor wrote:

              Yeah this is a harsh reply but in the future a more constructive answer is better

              You asked a specific question by making a specific statement. I quoted exactly that and addressed specifically that. Perhaps you can ask a more general question in the future. I will note that the following in google seems to address your general question however.

              example java send image by socket

              Valentinor wrote:

              or help them with a riddle that it is going to take them even farther from the solution.

              The forum is intended to provide answers to people that ask technical questions. It is not a forum on teaching people how to ask questions on forums.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups