|
From: ssecorp on 7 Jul 2008 14:43 I want to open a bunch of pictures and get their pixels. i want also to be able to display them this is easy enoguh in python but seems very complicated in Java. what library do you recommend? from PIL import Image import os print os.path.exists('C:/Users/saftarn/Desktop/images/blob.jpg') im2 = Image.open('C:/Users/saftarn/Desktop/images/blob.jpg') for x in range(1,200): for y in range(1,200): color = im2.getpixel((x,y)) if color != (255,255,255): print x,y,color
From: Joshua Cranmer on 7 Jul 2008 14:52 ssecorp wrote: > I want to open a bunch of pictures and get their pixels. > i want also to be able to display them > > this is easy enoguh in python but seems very complicated in Java. > > what library do you recommend? <http://java.sun.com/javase/6/docs/api/java/awt/image/PixelGrabber.html> does pixel grabbing. As for display, it's built in various places along the AWT and Swing frameworks. Check the Java tutorials for more information. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
From: Tom Anderson on 7 Jul 2008 15:23 On Mon, 7 Jul 2008, Joshua Cranmer wrote: > ssecorp wrote: > >> I want to open a bunch of pictures and get their pixels. >> i want also to be able to display them >> >> this is easy enoguh in python but seems very complicated in Java. import java.awt.image.BufferedImage ; import javax.imageio.ImageIO ; import java.io.File ; import java.io.IOException ; public void getPixels(String filename) throws IOException { BufferedImage img = ImageIO.read(new File(filename)) ; for (int y = 0 ; y < 200 ; ++y) { for (int x = 0 ; x < 200 ; ++x) { int p = img.getRGB(x, y) ; if (p != 0xffffff) System.err.println("" + x + ", " + y + ": " + Integer.toHexString(p)) ; } } } Doesn't seem complicated to me. You can do img.getRaster() and use that if you want more nuanced access to the pixel data. Displaying an image also isn't hard - it's not quite as easy as PIL's one-line version, but: import java.awt.Canvas ; import java.awt.Image ; import java.awt.Graphics ; public class ImageCanvas extends Canvas { private Image img ; private Dimension preferredSize ; public ImageCanvas(Image img) { this.img = img ; preferredSize = new Dimension(img.getWidth(), img.getHeight()) ; } public void update(Graphics g) { g.drawImage(img, 0, 0, null) ; } public Dimension getPreferredSize() { return preferredSize ; } } Then just make one and display it in a Frame. >> what library do you recommend? > > <http://java.sun.com/javase/6/docs/api/java/awt/image/PixelGrabber.html> does > pixel grabbing. > > As for display, it's built in various places along the AWT and swing > frameworks. Check the Java tutorials for more information. That's a weird little class. I think it's for extracting pixels from Images which are not necessarily BufferedImages, such as ones you get from the AWT toolkit. If you're using javax.imageio, you don't need to worry about this. tom -- There are lousy reviews, and then there's empirical shitness. -- pikelet
|
Pages: 1 Prev: Changing group permission using java in unix Next: Authentication in webapp. |