I have a console application which screen scrapes some data, and now I need to do image comparisons. If the images are different, I want to show the images to the user. What's the best way to display two images during the execution of a console application? I'm assuming I would use some sort of inter-process communication to send information back and forth, but I'm not sure how exactly I would go about doing that in a good fashion.
Also, I'd rather NOT store the images to files if possible. There's no reason to persist the data, and if the console application terminates unexpectedly, it's better if I don't have any dirt left on the file system.
Does anyone have any thoughts on how best to accomplish this?
I am not sure I understand the concern. You should be perfectly able to conditionally pop up either a Swing JFrame or AWT Frame from your console application, am I wrong?
You can use e.g. BufferedImage to construct images, or the utilities in javax.imageio if your image is already in some common format (e.g. PNG, JPEG, BMP). As for displaying to the user, just use the regular Java GUI stuff, either Swing or AWT. Run the GUI in a separate thread if the console part needs to keep processing while the images are being displayed.
The Working with Images tutorial may contain some helpful examples.
Related
I'm new to programming but I really wish to improve, right now learning Java. Basically there is this game, online strategy it's pretty basic with most of the images are static and very few of them change. I wish to change how I view the game from my end and add some functionality to it as well.
For example the website displays an orange rectangle, I wish to display a red rectangle by drawing over it. Or drawing a button when, if clicked, re-directs me to another part of the game. Originally I am using Selenium Chrome WebDriver to navigate the website but it seems you can't paint or display your own images over it. So I was wondering if I should use Selenium headless in the background performing tasks while I just make a Java Application. Make the WebDriver capture the image every second and display it on the Java Application every second, and than edit that image to my liking? Would this be effective way to do it or is there better options?
It is not clear what you are actually trying to achieve here. And whether your approach is likely to be "effective" depends what you are trying to achieve!
However, I can see some issues:
I don't know if it is technically possible to get the Selenium WebDriver to do that ...
Capturing images at a high rate could be problematic from a performance perspective.
Once you have captured the images:
Modifying the images by hand would be tedious and labour intensive. (And probably not what you want to do.)
Modifying static images programatically would be possible, but fiddly to implement and incredibly fragile. The slightest change to the game's screen rendering could result in your "tweaks" writing to the wrong place on the image.
Making changes to the dynamic part of images would be next to impossible ... except in the destructive sense.
You can't affect game play by this approach. Nothing you do to the images will impact on the browser and hence on the server. You can't add functionality this way.
In short, this is a poor idea, and unlikely to achieve anything worthwhile.
Can I think of any good options? No I can't.
The best I can think of would be to:
reverse engineer the HTML / Javascript uploaded to your browser,
figure out what you want to change in that content, and
place an HTTP proxy between your web browser and the server that injects the relevant changes into the content.
However:
It will be a lot of tricky and tedious work to implement.
It will be fragile; i.e. changes to the game / game server are liable to break your "hacks".
It could be a violation of the game owner's copyright and/or the license that grants you the right to use the game. This could result in your game accounts being cancelled, along with the accounts of anyone else who uses your "hacks".
My advice? Just play the game!
I want to create a print preview for a variable-size set of images in Java. My first approach (in dev mode) was to create snapshots of the images in different JLabels (just as a quick developer solution).
But for the production solution I need to create a more efficient and elegant way to display the images for the user of this standalone software. So I was thinking in showing him maybe 7-8 snapshots of the images to be printed on each JLabel.
Is there another way to do this? (Speaking of Java GUI components)
You can store these Images in some sort of List<Image>, such as ArrayList<Image>. Please read the Graphics2D tutorial, which contains related examples. There are other examples here.
I can't seem to find anybody who has done or posted something like this; Essentially I want to design my own UI in photoshop and then slice down the images to use it in a Java application. Essentially coding in the PSD file as the GUI. Is this possible? If so, can anybody lead me in the right direction?
I'm not sure what editor to use for this sort of stuff. I am using the Eclipse IDE and I know there is a Visual Editor but, I already have the actual design for every component in a PSD file. All I want to do is to start incorporating this into the application. Thanks.
It depends on how far your design goes. If you simply want to have normal Swing components on top of your image this is easy. Convert your PSD into (for example) PNG, create a custom JPanel subclass that loads the image and overwrite the paintComponent() method to draw the image instead of the normal background. All child components can then be set to be transparent with setOpaque(false). This puts your image into the background and puts the components float on top of it.
If you want to change how individual components look, its a lot more work. You basically need to implement a new Look&Feel for Swing. I wouldn't recommend going that route, unless you really have to, we are talking about weeks of work here, and it requires a lot of testing to really make it work properly on all platforms.
Alternately, there are already tons of custom Look&Feels available, I suggest you take a look at some freely available ones (just google "java look and feel"). Many of them can be customized to some degree (how much depends on the actual implementation, so take a close look at the source/documentation for each of them).
You might want to take a look at NetBeans which has a Swing GUI Builder. You would have to redraw your components there, and then write all the code to process the events. It is sometimes good to start with that, though often times it is less frustrating to lay them out with code by hand as it can difficult to make changes in code and have the builder keep up. There is nothing I know that will let you start from a photoshop image and proceed to building a GUI. Sounds like a good project to make someone rich. :-)
I'd like to "capture" a screenshot of what a java applet would currently look like if it were loaded, effectively screenshoting an applet without the use of a vdu.
The purpose of this is to display the image to a user that doesn't have a JVM. Lets assume the applet is a digital clock and has no requirement on user input. So what could be done is set up a pc connected to a vdu, open the applet, schedule a script to take a screenshot and upload the image. Clients could then access what the applet would look like at any given time without the requirement on a jvm.
It'd be such a hassle to have a pc running all the time etc. Surely this could be done somehow without a display.
Would it be possible to create a virtual display in a jvm that can render an applet and then take a screen capture?
If this were possible then perhaps a really high resolution display could be virtualized to create a very high resolution screenshot.
The ScreenImage class should handle this.
Look at java.awt.Robot#createScreenCapture(java.awt.Rectangle)
If this would work, i would wonder, remind the sandbox, and as the above link stated "This will work whether you have an AWT or Swing application."
If you use a "rendering-engine" (composing each pixel to something paintable before repaint()'ing) within you applet, you could use this information and create an image.
Is it possible to take a screen shot (using the Print Screen) and paste it from the System Clipboard directly into a web pages text area field (which I would create)? Do I need a browser plug-in? Can Flash do this?
**The solution only has to work in Internet Explorer.
This is not possible without a plugin.
It's not possible in Flash or Silverlight either, although it is possible in AIR.
I think you will have to write a custom ActiveX Control in order to do this. The control should automatically take a screenshot and send captured image to server-side code..
There is one more option - create a java applet, which will do the job, and also will help you to avoid cross browser issue.