I am using Codename One.
In my program I generate html code dynamically. I would like to grab a screenshot of the web browser view so I can send the screenshot as an image to users.
I've tried calling browserComponent.paint(Graphics) to draw this onto a mutable image but this resulted in a blank image. Is there a way to do this?
You can't grab a screenshot of a peer component.
HTML is rendered natively in the OS as a PeerComponent see this blog post explaining peer components. Unfortunately peer components are rendered separately so you can't grab a screenshot of a peer.
You can draw anything you want onto an Image using mutable images but you can't grab the image of an arbitrary peer. Check out our graphics section in the developer guide to see how one draws on an image.
Related
We are working on Tensorflow to train a dataset of images.
To get images we record video using our phones and, using OpenCV in Python we extract each frame and save them as JPG images. I rotate some of them to portrait mode with the Photos App on Windows 10.
Then, we have our own annotation tool written in Java to label each item we see on the images. It return a CSV file for each object with their coordinates (in percentage).
However, when I ran the training yesterday, I noticed via the tensorboard interface that some were not annotated rightly (the ones I rotated with Photos)
Here is the image opened on Tensorboard, you can see that the can is very badly annotated.
It turns out that if I open this image with our Java software it is well annotated, but as you can see below, the image is horizontal (it doesn't take in account the rotation applied with Photos) :
If I open it with Paint, or the explorer it appears in portrait mode like in tensorboard.
An other fact, If I send the picture via Facebook, and download it again, it will appear in portrait mode on the Java tool as it would have been from the beginning.
I tried to rotate the image with Paint this time, and it appears correctly in the Java tool.
The code that displays the image in Java:
panel.image = New File(srcFile);
The code that saves video frame in Python:
cap = cv.VideoCapture(video_path)
while cap.isOpened():
ret, frame = cap.read()
if ret:
try:
cv.imwrite(output_img_path, frame)
except Exception:
pass
else:
break
cap.release()
Do you know why Java ignores the rotation applied via the Win10 Photos software, why it works via Paint ?
Is there a way to make Java take it in account because it would be very unpleasant to start again from scratch.
Thanking you in advance,
After noticing that rotating images with Paint instead of Photos was giving what we wanted, I found out what was wrong.
"If you’re using Windows 10, File Explorer and the default image viewer will properly obey the Exif Orientation tag, so photos that come from your smartphone or digital camera will be display properly. Google’s Android and Apple’s iOS both natively create photos with the Exif Orientation tag and support it." (source)
I used JPG autorotate to fix this.
I was just wondering how to take a screenshot of my webpage. Lets say i have an interface around all borders, and in the middle is the frame that shows websites. How would it be possible to take a screenshot of that frame. I would not need any borders and interface included in that snap. Only the frame, how can it be accomplished?
I have included the picture which represents the layout of a website, so no need to include the entire layout but just this segment in the frame. How to capture that frame in an image programmatically? What tools and programming language can do this for me?
PhantomJS is a fully programmable headless browser. It is able to produce PNG, JPEG, GIF and PDF files from the web pages it opens.
Use document.querySelector(), then element.getBoundingClientRect() DOM APIs to get the rectangle containing the element you want to rasterize, then set webpage.clipRect property to it and call webpage.render() method to produce the image. See this answer for an example.
I do not know if you really have no limitations on the technology you wish to use, but phantomJS (headless browser) can certainly be use here. Example: How to render part of a page with PhantomJS
I have a project requirement to render HTML and capture the rendered image as a file on a headless CentOS 5.4 server. My specific requirements are:
1) Input will be a URL to the page to render (or file:// URL to a local HTML file), output will be an image file containing the rendered image of the page
2) CSS must be supported by the renderer up to CSS level-1
3) Static images in the page must be displayed properly in the rendered image, including any transparent color in .GIF or .PNG files
4) Must be able to run on a headless CentOS 5.4 server.
5) Solution must not depend on any product or component that is not free for commercial use
I do not need to do anything with the page other than get the screen capture and save it to an image. The hard part seems to be doing this in a headless environment. Some of the solutions that I've seen discussed need a display in order to work.
Any suggestions?
Thanks in advance,
Jim
SOLUTION:
I ended up using the Standard Widget Toolkit library (www.eclipse.org/swt) for its embedded browser capabilities. This allowed me to programmatically open a window with a browser control in it, render the page, then capture the content of the window to an image file (usually a PNG). The only downside to this approach that cannot be avoided is a "flicker" when the window must be made visible for a moment in order to do the screen capture. I can live with it. The rest was just code to initialize the SWT objects that obtain system resources, a listener to check for a successful completion of the page load, and some code to clean up a hung connection (when the page load never completes for whatever reason).
I got a teammate to play around with xvfb (X virtual framebuffer) on CentOS Linux. The initial tests appear to work, so it looks like the advice from the poster below (who said to try xvfb) may be a viable solution for the headless server part of my issue.
You can start a virtual X-windows environment using xvfb . You can now start a regular browser to render the page and use a screencapture utility to capture the content of the window. It is not pretty, but straghtforward to do.
WebKit is open-source and embeddable, maybe you can use this in a small native app to render on a canvas and save it to disk?
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.
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.