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

投稿

ラベル(Image)が付いた投稿を表示しています

Java: Extract Gif Images From an Animated Gif Image

In this post, I will show you the code for extracting gif frame images from an animated gif image. I will show you two types of code: Simply extracting gif images stored in the original animated gif image Creating gif image by rendering and accumulating each gif frames stored in the original gif image Code for Extracting Gif Image From An Animated Gif Java Code package com.dukesoftware.utils.image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; public class GifImageUtils { public static void main(String[] args) throws IOException { String sourceGif = "c:/temp/SmallFullColourGIF.gif"; saveAnimatedGifFramePartsToImage(sourceGif, "c:/temp/gif_parts"); } public static void saveAnimatedGifFramePartsToImage(String input, String outDir) throws IOException { ImageReade

Create Indexed PNG Using C# .Net

Currently I am working on optimizing image size. In this post, I will demonstrate the C# code for creating indexed png image. The code might not be perfect yet, but hope this code will give you some hints ;) A few things I am struggling with while I am writing the example code: Palette: you should take ColorPalette from Bitmap, modify the ColorPalette object and set buck it to the Bitmap object. BitmapData.Stride is often bigger than BitmapData.Width. You should be careful to check both values difference when you manipulating the image array index. The example code uses classes in System.Drawing namespace. But looks there is another option to manipulate image in C# .Net - System.Windows.Media namespace. C# Source Code for Creating Indexed PNG The following implementation of CreateIndexedPng method is able to take only non-indexed image like Format24bppRgb or Format32bppArgb. (I might add other image formats in future.) If the source image has only 2 colors, we can use For

Java: Create Indexed PNG Image Using Standard Java Image API

Hello guys! I have written Java: How to Create Indexed PNG Using PNGJ Library a few years ago. Recently I investigated how to create indexed png by standard Java image API. I have googled and tested various methods, finally I figureed out how to create indexed png image. Still my program is not perfect (of course most of the case it worked well), I believe that this program gives you the hint to creating indexed png and image manipulation on standard Java API. Code Actually the method is quite straigt forward. Please see the code below :) The advantedge of this code is the code doesn't require any library. The code below contains all of the stuffs needed for creating indexed png image! package com.dukesoftware.util.image; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.awt.image.ColorModel; import java.awt.image.DataBuffer; import java.awt.image.IndexColorModel; import java.io.File; import java.

Javascript: Lazy Load Image

I realized that most of the modern browser download the image which is set on src attribute even if the img element is hidden. This sometimes goes to performance problem because even if there are a lot of hidden image which are only shown user interacts, all images are downloaded initial page load! So I wrote a simple javascript for reflesh the src attribute and download image only when user interacts somethig on window - like press button etc. I know you can use JQuery LazyLoad plugin , but I would like to take much more faster solution - no external javascript. Here is the demo. When you push the button, the image is loaded lazyly Load image Here is the key method. (maybe you can check the logic by viewing the src directly though.) Replace the src attribute with data-original attribute i the img tag. function loadImage(elem) { if(elem.attr("src") != elem.attr("data-original")) { elem.attr("src", elem.attr("data-original&qu

Get Original Hi-res image from Zoomable image on Amazon

Some pages in amazon provide images which user can zoom on, like this page. The question is "Where is the original hi-resolution image?". You can easily find the explanation page for how to construct url for original hi-res image. (See this stack overflow page .) In this post I will show you the code snippet for getting original hires imgae from ASIN code. Note!: This method might be unavailable if amazon change the implementation of zoom and hires image url construnction. Code Actually code is nothing special. Just find " DynAPI.addZoomViewer( " . // pattern for extracting image code used for retrieving original image. private static Pattern AMAZON_ZOOM_IMAGE_PATTERN = Pattern.compile("DynAPI\\.addZoomViewer\\(\".+/(.+?)\",\\s*(.+?),\\s*(.+?),\\s*(.+?),\\s*(.+?),\\s*(.+?),.*\\)"); public static String findOriginalZoomImageUrl(String asin, String country) { String url = getAmazonZoomImageWindowUrl(asin, country); try{

How to pick up Hi-Resolution Image from Amazon product page

Recently I realized that Amazon offers high resolution photos in some products. I have found the way to extract these hires images. Note Note!: This method might be unavailable in the future because Amazon may not like this kind of hack or change the implementation :P Basic Strategy For example, this page: http://www.amazon.com/Silver-Violin-Nicola-Benedetti/dp/B008CYV046/ If you see the html source of this page, you can find the following json string. var colorImages = {"initial":[{"large":"http://ecx.images-amazon.com/images/I/XXXXXXX.jpg",.... It represents the urls of various size of images. If you would like to see the hi-resolution image, you should pick up the url which is defined in hiRes property. Source Code You know I still like Java, I will show you the simple Java code. I use Jackson for parsing JSon string. import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; imp

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.

C#: How to Read Image as Double Array (for Image Processing)

As you know I am really interested in image processing. For my first step, I wrote the program for reading image as double array in C#. The code is imperfect but I think this will help someone's understand.... Here is an example usage. var original = Bitmap.FromFile(@"C:\temp\test.jpg"); double[,] values = new Bitmap(original).To2DimDoubleArray(); // image processing part! // let's do something fun :D - filtering, binalizing, etc. // for now, removing R value from the image. for (int i = 0, len = values.Length/values.GetLength(0); i < len; i++ ) { //values[0, i] = 0; // a values[1, i] = 0; // r //values[2, i] = 0; // g //values[3, i] = 0; // b } values .ToBitmap(original.Width, original.Height, PixelFormat.Format32bppArgb) .SaveImageAsJpeg(@"c:\temp\test2.jpg", 75); The image processing result of above example program. The left image is original, the right image is the result image which is red value is removed.