We are about to switch to a new forum software. Until then we have removed the registration on this forum.
in Server sketch, i take a picture with Processing’s Video library and send a byte array to client’s buffer
like this,,
/**
void mousePressed() {
capture.save(“temp.jpg");
byte[] b=loadBytes(“temp.jpg");
server.write(b);
}
*/
but i have no idea how to convert this byte array to PImage format in Client’s sketch.
is there any byte[] to Pimage converting method in processing???
Answers
There does not appear to be one, but here is the relevant code that Processing uses to load in jpg files:
I must say it seems like a suboptimal way to do it. There should be no need to write a temp jpg file to disk just to load it in again (unless you need that file on your disk of course). Maybe something like
server.write(capture.pixels)
works. Be aware that the PImage pixels array is not the same as a jpg pixels array.I hope they were careful enough to use toLowerCase() on extension:
extension = extension.toLowerCase();
http://docs.Oracle.com/javase/8/docs/api/java/lang/String.html#toLowerCase-- :-S
If what I see is the whole code, Processing will always miss uppercase picture extension names like ".JPG", ".Png", etc.!!! 8-}
Yes they do, I did not post the whole loadImage() method, only the relevant part.
For clarity I meant to say that Czerny's way was suboptimal as it involves writing a PImage to disk as a jpg (which involves taking a Fourier transform of the image), read it in again as bytes, send it to the server and convert it back to a PImage, while you could send the PImage as bytes directly using its internal pixels array.
Based on my solution "aRGB_Shifting_Conversion" here:
https://forum.Processing.org/two/discussion/13411/how-to-write-a-large-int-as-as-bytes
I did "Pixels[]_To_Byte[]_Conversion" for this thread using Server & Client too:
https://Processing.org/reference/libraries/net/index.html
The new extra function is from_pixels_to_byte_array(), which invokes to_aRGB_array():
Differrent approach but same isse. I have some uuencoded PNG's and JPG's. Decoding is pretty easy. After saveByte pictures can be viewed. But I want to display them without to store them on disk. Using avtImage and conversion to PIMage failed. Any hints or ideas?
THX f41ardu