スキップしてメイン コンテンツに移動

投稿

Java: Capture Web Page

Recently I was investigating how to capture web page as image. I recently realized that there is a nicer nice component for navigating web page in Java FX. javafx.scene.web.WebView javafx.embed.swing.JFXPanel I referred this stackoverflow post and wrote a Java class for capturing web page and save it as image. Please note that you should include jfxrt.jar, which was in JDK1.7.0_XX/jre/lib, should be added to your classpath. Code Here is an actual code. Please feel free to use it... I am very happy if you give me some feedback for this code. package com.dukesoftware.javafx; import static com.dukesoftware.utils.io.IOUtils.getExtension; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue;

ActionScript 3.0: Capture Web Page Image

In my recent post, I was trying to find out easy way to capture we page image. Today, I will show you my small code tip for capturing web page and saving it as image by ActionScript 3.0. WebPageCapture class This is the main class for capturing web page and save it as image. A few points I should comment... In captureAndSave method, I have used timer because even after Complete event is triggered, somehow sometimes web page is not rendered properly... (might be depends on web site or lazy javascript loading.) requstQueue field is for making sure the request is processed one by one after the former image capturing request is done. You can avoid this if you create HTMLLoader instance for each request. Looks default JPEGEncoder is quite slow.... I have googled and found the following great article. If you are interested in performance, see this excellent post . I was amazed actually :D If you are interested in asynchronous encoding, see this marvelous post . I was impressed :D

Create Web Page Thumbnail by Java or C#

I have googled how to create web page thumbnail. Hope this post helps anyone who are trying to create web page image. Java Lunch a native browser from Desktop class and capture active window by Robot class I think this isn't smart way however it should work. Please read this . The disadvantage of this method is you cannot achieve it on off screen. Using SWT Browser Please read this . The biggest disadvantage is again you cannot do it on off screen. Pure Java Solution If you are seeking pure java solution, maybe Cobra or Css Box will help you. Unfortunately Cobra is not updated recently, and Css Box is still very new on the other hand. I hope I can post example of code on this blog in near future.... Using QT-Jambi I'm not familiar with Qt library but this post explains how to create web page image by Qt Jambi , which is java wrapper of Qt Library. The post provides code example, too!! C# Using System.Windows.Forms.WebBrowser this article in www.codeproj

Java: How to Manipulate Image as Double Array (Read and Write)

Read Image as Double Array You might think "We can use Raster#getPixel method if we would like to grab pixels, can't we?". Yes that's true. The key problem is the low performance because getPixel method internally call SampleModel and convert raw value to proper pixel value every method call. So we should call Raster#getPixels method and grab all pixels one method call. I have done similar stuffs in C# and posted on this blog. On the other hand in Java, this is a bit messy because there are a lot of related classes - Raster, ImageIO, Reader, Writer, etc ;). The simplest way I did is: read image as BufferedImage by ImageIO call BufferedImage#getRaster method call Raster#getPixels method Here is an exmple code. public static TemporalImage readImagePixelDoubleArray(InputStream is, int bitPerPixel) throws IOException{ BufferedImage image = ImageIO.read(is); Raster raster = image.getRaster(); int x = raster.getMinX(); int y = raster.

Java: How to Load Classes at Runtime from Jar or Class Files

I wrote java program for loading classes at runtime from jar file or class files Hope this post will help somebody... package com.dukesoftware.utils.reflect; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class DynamicClassLoader { public static List<Class<?>> readAllClassesFormJarFile(File jarFilePath) throws IOException{ List<Class<?>> classes = new ArrayList<>(); URL[] urls = { new URL("jar:" + jarFilePath.toURI().toURL() + "!/") }; URLClassLoader loader = URLClassLoader.newInstance(urls); for(Enumeration<JarEntry> en = new JarFile(jarFilePath).entries(); en.hasMoreElements();){ final String name = en.nextElement().getName(

Java: How to Create Indexed PNG Using PNGJ Library

I'm working on Google App Engine for Java (GAEJ) now. Very excited about working on it because can develop Java Web App quite easliy & quickly! However I faced a limitation of image processing on GAEJ. On GAEJ, java.awt pakage.* is not supported. That means we cannot use BufferedImage etc!! As you know, Google provides com.google.appengine.api.images.* for image processing on GAEJ, something like below: ImagesService imagesService = ImagesServiceFactory.getImagesService(); Image srcImage = ImagesServiceFactory.makeImage(srcImageData); // some transformations. Transform crop = ImagesServiceFactory.makeCrop(0.3, 0, 1, 0.70); OutputSettings settings = new OutputSettings(OutputEncoding.PNG); // apply transform Image newImage = imagesService.applyTransform(crop, srcImage, settings); byte[] newImageData = newImage.getImageData(); It can read jpg, png, gif images accroding to the official document. And if transformation is applied, the output binary data becomes png forma

The Easiest Way To Getting XPath of Html Element

Some of you feel a bit annoying for writing XPath to specify html element in Selenium Test. I think the easiest way is using Chrome or using Firebug of Firefox. Chrome Right click html area you would like to get XPath, and select "Inspect element" Right click the html element and select "Copy XPath" in the opened area Firebug Right click html area you would like to get XPath, and select "Inspect Element with Firebug" Right click the html element and select "Copy XPath" in the opened area