Sending BufferedImage thought a socket
-
Can you send a
BufferedImage
thought a socket by changing it somehow because it is notSerializable
, and then on client side usingWritableImage
to show it inside aImageView
? 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 insideImageView
:Robot robot = new Robot();
BufferedImage imageB = robot.createScreenCapture(screenRectangle);
WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
ImageView.setImage(imageW); -
Can you send a
BufferedImage
thought a socket by changing it somehow because it is notSerializable
, and then on client side usingWritableImage
to show it inside aImageView
? 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 insideImageView
:Robot robot = new Robot();
BufferedImage imageB = robot.createScreenCapture(screenRectangle);
WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
ImageView.setImage(imageW);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.
-
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.
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.
-
Can you send a
BufferedImage
thought a socket by changing it somehow because it is notSerializable
, and then on client side usingWritableImage
to show it inside aImageView
? 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 insideImageView
:Robot robot = new Robot();
BufferedImage imageB = robot.createScreenCapture(screenRectangle);
WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
ImageView.setImage(imageW);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
-
Can you send a
BufferedImage
thought a socket by changing it somehow because it is notSerializable
, and then on client side usingWritableImage
to show it inside aImageView
? 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 insideImageView
:Robot robot = new Robot();
BufferedImage imageB = robot.createScreenCapture(screenRectangle);
WritableImage imageW = SwingFXUtils.toFXImage(imageB, null);
ImageView.setImage(imageW);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.
-
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.
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.