|
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);
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
For given numbers N and K, write a function to find 'significant number'. Let's look at an example to understand the steps to find 'significant number'.
Given N = 46333 and K = 3,
1. Check if N is 'reversible' or not. ['Reversible' denotes a number sequence that reads the same backward as forward, e.g., 12321]
If Yes, return 1.
If No, go to step 2.
2. Convert digits of N to elements of array A.
e.g. For N = 46333
Convert to array A = [4, 6, 3, 3, 3]
3. Replace each element of array A with its 'modified value'.
Modified value of A[ i ] = A[ i ] * 5;
Modified value of 4 is = 4*5 = 20
Modified value for 6 is = 6*5 = 30 and so on.
After replacing elements of array A with their 'modified values', array A will be [20, 30, 15, 15, 15]
4. For each element in the array generated in previous step, find the 'child primes' that are less than the array element. Then, generate the sum of these child primes.
A child prime is a number in the form (2 * p) + 1 where p is prime.
[Prime numbers are 2, 3, 5, 7, 11 ...]
For A[0] = 20,
for prime number 2, (2 * 2) + 1 = 5 < 20
for prime number 3, (2 * 3) + 1 = 7 < 20
for prime number 5, (2 * 5) + 1 = 11 < 20
for prime number 7, (2 * 7) + 1 = 15 < 20
for prime number 11, (2 * 11) + 1 = 23 > 20. Hence, will not consider 23.
So, child primes less than 20 are [5 7 11 15]. Sum of child primes for array element A[0] is = 38
Similarly for A[1] = 30, child primes that are less than 30 are [5 7 11 15 23 27]
Sum of child prime for array element A[1] is = 88 and so on.
Array is now = [38 88 23 23 23]
5. Count pairs of the array generated in previous step whose sum is divisible by value K=3.
Here pairs which are divisible by 3 are (38,88), (88,23), (88,23) and (88,23).
Hence, return 4. This is the 'significant number' to be returned.
Input
46333
3
where,
First line represents value of N
Second line represents value of K
Expected Output
4
|
|
|
|
|
|
In most of scripting/interpreting programming languages such as python or JavaScript, there is/are a/some method(s) to execute a string in runtime just like a code.
For example: eval("int i=5;");
those could have run the eval method inside the interpreting shell and even inside the input parameter of eval method recursively without a problem.
In jshell I found, inside the java host program after creating a jshell object we can call the eval, but what if I want to insert the eval inside the string and then run it in the jshell object.
For example:
JShell jsh=JShell.create();
jsh.eval("int j=4;");//current way of using eval in jshell hosted by another java or jshell program.
I need to do something like this:
JShell jsh=JShell.create();
jsh.eval("""
eval("int j=4;");
""");
or alternatively
JShell jsh=JShell.create();
jsh.eval("""
currentJShell.eval("int j=4;");
""");
or again alternatively
JShell jsh=JShell.create();
jsh.eval("""
currentJShell.eval("int j=4;");
""");
after some research, I found something like "/open" doesn't solve the problem for multiple reasons:
1- it's a part of interactive jshell utility/UI (provided (probably) by oracle(not sure))
not exactly jshell object
2- even if it is a part of jshell, still inside the guest jshell program, I can't call it
in a for loop or ... I have to type it with the keyboard and then hit enter.
for(int c=0;c<34;c++){/open <filename+c>}// it's not possible.
But in beanshell looks like ok just like python and JavaScript.
I have the same problem with csharp script.
Thanks for your time.
Sorry if this question is asked in the wrong spot. I am not very familiar with these types of q/a website.
|
|
|
|
|
Majid Karimi wrote: Sorry if this question is asked in the wrong spot
Your question is really about how the jshell works and not really about java.
Majid Karimi wrote: JShell jsh=JShell.create();
Did you try creating a new shell in the eval. Pseudo code like the following
JShell jsh1=JShell.create();
jsh.eval("""
JShell jsh2=JShell.create();
jsh2.eval("int j=4;");
""");
Also note that presumably you are doing this to experiment. You would not want to create application code like this. That is due to complexity and maintenance costs.
|
|
|
|
|
I've been dealing with a problem in my application that has me forced to change the HibernateQuery in a way that casts the existing DateTime column I have within my database into a date for further processing.
I've looked around a little on here already and found a supposed solution using sqlGroupProjection which ended up looking like this for me.
Projection dp = Projections.sqlGroupProjection("CAST("+sp.getIname()+" AS DATE",
"CAST("+sp.getIname()+" AS DATE",
new String[] {sp.getIname()},
new Type[] {StandardBasicTypes.DATE});
This does work to some the extent that it now generates this in the SQL statement
CAST(ierstelltAm AS DATE)
Which would be correct if it wasn't for the fact that something is now missing. Usually when Hibernate generates these statements they're given unique identifiers, one of them being y[i]_ and the other somehow relating to the table/entity used in the syntax of entity[i]_.
Since these are all inbuilt hibernate functions I had expected the above method to generate something along these lines
CAST(auftrag8_.IErstelltAm AS DATE) as y1_
based on the fact that the code previously generated using the criteria system did look like this.
auftrag8_.IErstelltAm as y1_
The question is now how do I correctly cast something to another data type using hibernate criterie, if it's not the sqlGroupProjection method mentioned in other places -- or is this a syntactical/logical error on my part?
|
|
|
|
|
How to make a scrolling background for a JPanel in java? I tried searching google but couldn't find a helpful one.
|
|
|
|
|
Do you mean manual scrolling, or something that scrolls by itself? And how would that affect any other controls that are in the panel?
|
|
|
|
|
I have a jpanel with an image as a background . how can i make that scroll like in a game ?
|
|
|
|
|
|
sir i don't want scroll panes . i want my jpanel background image to scroll horizontaly automatticaly.i am making a game.
|
|
|
|
|
|
But I have seen many people making that using pure java. Sir please if it is not possiblie Please help me for this:-
I am using this code to make an image the background of a jpanel -
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(bgImage, 0, 0, null);
}
Sir how can make the background a gif using this code. Sir please help me. I beg.
|
|
|
|
|
|
Sir you are the only one who replied to my questions. I am very very thankfull for you.
|
|
|
|
|
Hi, I'm a student of Computer Science I have a little task which is I want to read the certificate from USB Token(Entersafe PKI Manager - Epass2003 Auto) and after that, I print it on the Eclipse Console using Java Can Anyone Help me please with this solution.
|
|
|
|
|
I am an absolute beginner in java and l want to practice java code in eclipse code editors. I want to know that do l have to set up the environmental variables first to run programs in eclipse? And also is there will be any harm or changes to my system after setting variables? Please help me..
|
|
|
|
|
|
Recently, l have downloaded jdk in my Windows 10. Now, l didn't rememberd which version of jdk l have installed in my system. I want to know that which version of jdk is installed in my Windows. Please help me.
|
|
|
|
|
java -version
Type that command at the console. And try making use of the documentation.
|
|
|
|