Getting a pixel in an image

How can i get the color of a pixel in an Image object, or an array of bytes or integers of the image.

use getRGB(int x, int y) method of BufferedImage.
first convert your image object to bufferedImage object. then use above method.
if any problems contact
[email protected] or [email protected]
best of luck!

Similar Messages

  • Getting a pixel between thumbnail images

    Hi Folks
    I am using a CellRenderer to display thumbnail images,and I want to
    keep a distance of 1 pixel between the images.
    What can I do to get this?
    Attached is my renderer
    public FTRDPictureChooserDateAndTimeCellRenderer(){
         thumbnailImage    = new JLabel();
         imageText         = new JLabel();
         dateAndTimeLabel  = new JLabel();
         gbl = new GridBagLayout();
         setLayout(gbl);
         gbc = new GridBagConstraints();
         gbc.gridx      = 0;       // x represents cols
         gbc.gridy      = 0;       // y represents rows
         gbc.gridwidth  = 1;               // reset to the default
         gbc.gridheight = 2;       // span 2 rows to display image.
         gbc.weighty    = 1.0;
         gbc.weightx    = 1.0;
         add(thumbnailImage,gbc);
         /* Image Name */
         gbc.gridwidth  = GridBagConstraints.REMAINDER; //end row
         gbc.gridheight = 1;     
         gbc.gridx      = 1;          
         gbc.gridy      = 0;
            add(imageText,gbc);                                                      
         setOpaque(true);
                                                                          

    Well, let's see... now if I look at the API docs for
    GridBagConstraints, I see it has fields: ipadx and
    ipady ... I wonder what they do?They pad inside the component so won't actually help. However, the insets field will allow you to define the number of pixels to pad outside the component. So you can either do gbc.insets = new Insets(0,0,0,1) from the first component or gbc.insets = new Insets(0,1,0,0) for the second one. Either will add a single pixel between them.
    Ian

  • How do you reduce the pixels of an image to fit within certain requirements

    I am trying to get the pixels of an image to fit certain requirements. When I try to edit the image in iPhoto by clicking custom constrain and then enter the pixel of dimensions I want, it will not adjust the image to them. Does anyone know how I can do this?

    Select the pic in the iPhoto Window and go
    File -> Export
    in the resulting dialogue you can resize:
    Uploaded with plasq's Skitch!
    Regards
    TD

  • How can I get to read the pixels in an image?

    Please see details of my code below. What I am doing is trying to obtain the pixels for an image. there is an initial image of a certain size, which is then split into smaller portions.
    The problem I'm getting is that pixels can not be read past the middle of the original image. I hope I have explained this so it can be understood. I have included the class that I am working on
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package MandelbrotConstruction.compression;
    import java.awt.*;
    import java.awt.color.ColorSpace;
    import java.awt.geom.AffineTransform;
    import java.awt.image.*;
    import java.io.*;
    import java.util.ArrayList;
    import javax.imageio.ImageIO;
    import javax.swing.JPanel;
    * @author Charlene Hunter
    public class DisplayImg extends JPanel {
        private static BufferedImage image;
        private static ArrayList<Range> rangeLot;
        private static ArrayList<Domain> domainLot;
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            int w = MainFrame.getJPanel1().getWidth();
            int h = MainFrame.getJPanel1().getHeight();
            Graphics2D g2 = (Graphics2D) g;
            File img = MainFrame.getImgFile();
            image = null;
            if (img != null) {
                try {
                    image = ImageIO.read(img);
                    //filter the image with a grayscale
                    ColorConvertOp grayOp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
                    image = grayOp.filter(image, null);
                    //scale image to the size of the panel
                    AffineTransform at = new AffineTransform();
                    at.scale(256.0 / image.getWidth(), 256.0 / image.getHeight());
                    AffineTransformOp resizeOp = new AffineTransformOp(at, null);
                    image = resizeOp.filter(image, null);
                    ArrayList<Range> r = createRanges(image, 3);
                    ArrayList<Domain> d = createDomains(image);
                    int i = 0;
                    for (Domain dom : d) {
                        System.err.println("this is " + i);
                        System.out.println(dom.getPixels());
                        i++;
                    CompareClass comparer = new CompareClass(r, d);
                } catch (IOException e) {
                    System.err.println("IOException");
            g2.drawImage(image, null, 0, 0);
        public static ArrayList<Range> createRanges(BufferedImage bi, int divisions) {
            int w = bi.getWidth();
            int h = bi.getHeight();
            rangeLot = new ArrayList<Range>();
            int k = (int) Math.pow(2, divisions);
            for (int x = 0; x < w; x = x + (w / k)) {
                for (int y = 0; y < h; y = y + (h / k)) {
                    BufferedImage range = bi.getSubimage(x, y, w / k, h / k);
                    double[] pix = range.getRaster().getPixels(x, y, range.getWidth(), range.getHeight(), (double[]) null);
                    Range r = new Range(x, y, range, pix);
                    rangeLot.add(r);
            return rangeLot;
        public static ArrayList<Domain> createDomains(BufferedImage bi) {
            int w = bi.getWidth();
            int h = bi.getHeight();
            domainLot = new ArrayList<Domain>();
            int step = 4;
            for (int x = 0; x < w - step; x = x + step) {
                for (int y = 0; y < h - step; y = y + step) {
                    BufferedImage domain = bi.getSubimage(x, y, 2 * step, 2 * step);
                    double[] pix = domain.getRaster().getPixels(x, y, domain.getWidth(), domain.getHeight(), (double[]) null);
                    Domain d = new Domain(x, y, domain, pix);
                    domainLot.add(d);
            return domainLot;
    }If what I have included is not sufficient, please let me know. the problem is only arising when the pixels are being obtained for the subimage
    Thanks

    Hi, the error message I am getting is (i'm printing out the x,y values and width and height so that I can see what going on) the whole image is 512x512, and I am grabbing pixels for squares of 64x64, but when it gets to 256 it throws an exception. I don'd understand why
    (x: 0, y: 0)
    width: 64, height: 64
    done!
    (x: 0, y: 64)
    width: 64, height: 64
    done!
    (x: 0, y: 128)
    width: 64, height: 64
    done!
    (x: 0, y: 192)
    width: 64, height: 64
    done!
    (x: 0, y: 256)
    width: 64, height: 64
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
            at java.awt.image.ComponentSampleModel.getSampleDouble(ComponentSampleModel.java:807)
            at java.awt.image.SampleModel.getPixels(SampleModel.java:823)
            at java.awt.image.Raster.getPixels(Raster.java:1613)
            at MandelbrotConstruction.compression.DisplayImg.createRanges(DisplayImg.java:83)
            at MandelbrotConstruction.compression.DisplayImg.paintComponent(DisplayImg.java:51)
            at javax.swing.JComponent.paint(JComponent.java:1006)
            at javax.swing.JComponent.paintChildren(JComponent.java:843)
            at javax.swing.JComponent.paint(JComponent.java:1015)
            at javax.swing.JComponent.paintChildren(JComponent.java:843)
            at javax.swing.JComponent.paint(JComponent.java:1015)
            at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
            at javax.swing.JComponent.paintChildren(JComponent.java:843)
            at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4979)
            at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
            at javax.swing.JComponent.paint(JComponent.java:996)
            at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
            at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
            at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
            at java.awt.Container.paint(Container.java:1709)
            at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
            at sun.awt.RepaintArea.paint(RepaintArea.java:224)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
            at java.awt.Component.dispatchEventImpl(Component.java:4060)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Window.dispatchEventImpl(Window.java:1791)
            at java.awt.Component.dispatchEvent(Component.java:3819)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

  • Get the color of a pixel in an image

    how can i do to get the color of a pixel in an image ???
    Can anyone help me ?

    Hi,
    first of all you need to get the library to transfer your image to java.awt.image.BufferedImage object.
    I know many such libraries. Its depends of what kind of image you have: jpeg, gif, png or other.
    And when you get the BufferedImage of you picture using library, then you can get the color of any pixel in image using int BufferedImage.getRGB(int x, int y) as integer value.
    Victor Letunovsky

  • Adobe Standard 9.5.2 after update I get "Insufficient data for an image" error

    After updating to Acrobat Standard and Readre 9.5.2, some (but not all) of my pdf files are now opening with the error "Insufficient data for an image." The files open, but they are fuzzy, pixelated and are missing the bates stamp I applied earlier (using a utility from LexisNexis Casemap). I can open the files fine on another computer with Acrobat Standard 9.5.1.
    How can I uninstall the 9.5.2, or get it to work again?

    Windows 7 64-bit with Samsung SSD on an i5 Lenovo laptop. Yes, I have both Acrobat Standard and Reader 9.5.2 on the machine. Both give the same error when opening the attached file.
    -Dan-
    [email protected]
    Date: Thu, 16 Aug 2012 23:06:52 -0600
    From: [email protected]
    To: [email protected]
    Subject: Adobe Standard 9.5.2 after update I get "Insufficient data for an image" error
        Re: Adobe Standard 9.5.2 after update I get "Insufficient data for an image" error
        created by vamalik in Acrobat Installation & Update Issues - View the full discussion
    Hi osieko,Can you share across any such sample pdf file? Also, what OS are you working upon?You have both Acrobat Standard 9.5.2 and Reader 9.5.2 installed on your machine. Right? One option that you can try is to repair your Acrobat/Reader from Programs in Control Panel and see if that resolves the issue.Otherwise kindly attach a screenshot of the error you are receiving along with any sample pdf file.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4627764#4627764
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4627764#4627764. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Acrobat Installation & Update Issues by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • Please help me!--rendering makes the images or video blurry (very pixelated) deteriorates the image  Adobe Premier Elements 13  need help!  .jpg and mpeg images,  but I have never "rendered" before since I got APE 13 about 6 weeks ago.  I am desperate for

    Please help me!--rendering makes the images or video blurry (very pixelated) deteriorates the image  Adobe Premier Elements 13  need help!  .jpg and mpeg images,  but I have never "rendered" before since I got APE 13 about 6 weeks ago.  I am desperate for assistance!

    That's going to be a ridiculous waste of money and energy.
    First of all, the current ATI drivers don't support multiple GPUs, so at the moment even a single 4870X2 would be only a 'normal' 4870 (which is quite a speed beast already). GFX drivers evolve rapidly, so things might look different next month, but when it comes to Linux and hardware there's one Golden Rule: stay away from the newest stuff and wait for proper support to get coded.
    I also wonder what power supply could possibly cope with the differences between idle and full load; that's way beyond 400W. But then, I'm one of those "quiet&green" types where >100W idle is already a bit much.
    I kind of understand that you want to get it done and not worry about hardware for the next 10 years or so, but that's simply not how the hardware world works and never did. At least not for the average consumer.

  • Color overlay on opaque pixels of transparant image

    Hi everyone!
    I'm having a little problem here... I have loaded a gif image (a bufferedimage) in my program and I would like to have a color overlay on it. However, the overlay should only reside on the opaque pixels and not on the transparant parts of the image.
    I have looked for about an hour on this board to find the solution to my problem, but I haven't found anything useful. I did find the following, but it's not for a bufferedimage :(
    int pixels[][] = grabPixels(sprite);       
         // 2) Place the opaque pixels in a polygon
         Polygon poly = new Polygon();
         for (int y = 0; y < spriteH; y++) // y coordinate
              for (int x = 0; x < spriteW; x++) // x coordinate
                   if (pixels[y][x] != TRANSPARENT) {
                        poly.addPoint(x,y);
         }This code creates a polygon with the opaque pixels of the image I think. Too bad it's not for a bufferedimage!
    Thanks ahead!
    Jens

    Thanks, Randy. That's ingenious, but it doesn't seem to work very well, since the finished image looks like Frankenstein's monster, with half the guy's face looking one way and the other half another way. But ingenious.
    I don't mind using the limit effect if that is the best way to deal with my little problem. Just trying to get a consensus on what to do, after I put a contract out on this shooter.
    Thanks.
    Giraut

  • Quickest way to find the darkest pixel in an image

    I was wondering what the absolute fastest way to grab the darkest pixel(grayscale) in a picture. Or if anyone could give me any ideas on how one would go about making a fast dark pixel finder.

    Is the image Greyscale or RGB?
    Either way - you can access the data by getting the Raster
    Raster r = image.getData()
    Lookup the methods on Raster - you can access the data as one array.
    If the image is RGB - you will have to convert it to a Greyscale value (you let the JVM do it by creating a new Greyscale image and drawing to it, or doing it yourself by access each one and performing the math)...
    Lemme know...

  • GetImagePixelPointer in IMAQ Vision hangs while trying to get a pixel pointer.

    I have written several dll functions to do specific image processing. I have been successfully calling these dlls for some time. In rewriting my code to parallelize some activity, a single instance has come up where GetImagePixelPointer starts to execute but never returns. The instance appears to be related to a single image. I have looked backwards in my code and I am pretty sure that I unmap the pixel pointer from the previous time it gets used.
    Does anyone have any advice? What would cause GetImagePixelPointer to hang in the Map mode?

    Hey Matt,
    You mentioned things were working fine until you parallelized the code (you made multiple threads I assume). You also mentioned when you tried reproducing the problem, it worked fine. It sounded like if you took out the call to GetPixelValue in your original code that didn't work, it worked (is this correct). One of the problems I could see that having multiple threads might cause is if you create the image in a different thread than where you try and get the pixel pointer. The different threads have their own place on the heap and one thread's memory allocations may not be available to other threads.
    If you're still having problems, see if you can make a small snippet to reproduce (you will probably have to use multiple threads to reproduce this problem)
    Hope
    this helps,
    Brad Buchanan
    National Instruments

  • SWF Panel: how to get/set pixel or better - grab and paste BitmapData

    Hi everyone,
    trying to understand how to read and write pixel color from image or better - current layer but can't understand how to do this. Does this even possible? Main idea - it's pick current layer, put it to the SWF Panel. Doing there some modifications and back to Photoshop or write it by pixel. Doesn't matter.
    How know?
    I'm using Win7 x64, Photoshop CS6

    We don't have a direct way of getting the pixel data back and forth from a panel.
    You could try to get a socket connection via the Connections SDK and get pixel data that way. Not sure how much effort that would be. There is an AIR example in the connections SDK but I'm not certain if the socket interface will work inside of the SWF Panel.
    Telling Photoshop to write them out to disk and then read them into your panel would probably be pretty clunky.

  • Do you know how to keep from getting missing pixels?

    Dear fellow Photoshop Beginners,
    I am having an issue making a texture for a school project. Everytime I duplicate a layer and then "ctrl + T" to align the texture, I end up getting missing pixels along the edges of the duplicates even after I merge the layers. The original image is on the left and the duplicates are snapped to the right to create an elongated texture. I am using CS6. Do you know how to duplicate a layer without missing pixels on the edge?

    Hmm, I tried it myself and at 25% view I did see a line between the original and the duplicate:
    However, zooming in to 100% there was no border between the images, and looking at the individual pixels (600%) showed that there were no missing pixels.
    I'm wondering, what is the final purpose for this pattern, and what is the final file format? What happens when you view your image at 100%?

  • How to get max 5 color from image??

    I try to get max 5 color from image (ex. jpeg,gif) ,I use PixelGrabber
    it too slowly when i use large image,Please help me, to run more fast
    (other way PixelGrabber)
    best regard
    [email protected],[email protected]
    source below:
    public String generateColor(InputStream source,String filePath){
    BufferedImage image = null;
    String RGB = "";
    System.out.println("==generateColor==");
    try {
    image = ImageIO.read(source);
    catch (IOException ex1) {
    ex1.printStackTrace();
    //image.getGraphics().getColor().get
    // BufferedImage image2 = ImageIO.read(source);
    // image.getColorModel().getNumColorComponents()
    if(image.getColorModel() instanceof IndexColorModel) {
    IndexColorModel icm = (IndexColorModel)image.getColorModel();
    byte[][] data = new byte[3][icm.getMapSize()];
    int[] rgbB = new int[icm.getMapSize()];
    icm.getRGBs(rgbB);
    String dataHtm = "<HTML><table width=\"100\" border=\"0\"><tr>";
    for(int i = 0 ;i< rgbB.length;i++){
    int r = (rgbB[i] >> 16) & 0xff;
    int g = (rgbB[i] >> 8) & 0xff;
    int k = (rgbB) & 0xff;
    System.out.println("red:" + Integer.toHexString(r));
    System.out.println("green:" + Integer.toHexString(g));
    System.out.println("blue:" + Integer.toHexString(k));
    dataHtm = dataHtm + "<td width=\"10\" bgcolor=\"#" + Integer.toHexString(r)+Integer.toHexString(g)+Integer.toHexString(k);
    dataHtm = dataHtm + "\"> </td>";
    dataHtm = dataHtm + "</tr></table></HTML>";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("c:\\23289207.html"));
    out.write(dataHtm);
    out.close();
    catch (IOException e) {
    e.printStackTrace();
    int w = image.getWidth();
    int h = image.getHeight();
    int[] pixels = new int[w*h];
    int[] pixs = new int[w*h];
    System.out.println("image width:"+w+"image hight:"+h+"image w*h:"+(w*h));
    Image img = Toolkit.getDefaultToolkit().getImage(filePath);
    PixelGrabber pg = new PixelGrabber(img, 0,0, w, h, pixels, 0, w);
    try {
    pg.grabPixels();
    catch (Exception x) {
    x.printStackTrace();
    String picColor = "";
    Stack stackColor = new Stack();
    Hashtable hashColor = new Hashtable();
    for (int i = 0; i < w * h; i++) {
    int rgb = pixels[i];
    int a = (rgb >> 24) & 0xff;
    int r = (rgb >> 16) & 0xff;
    int g = (rgb >> 8) & 0xff;
    int k = (rgb) & 0xff;
    i = i+1000;
    //System.out.println("i:" + i);
    picColor = convertToSring(r)+convertToSring(g)+convertToSring(k);
    stackColor.add(picColor);
    //System.out.println("picColor:"+picColor);
    // System.out.println("\n\n a:" + a);
    // System.out.println("red:" + r);
    // System.out.println("green:" + g);
    // System.out.println("blue:" + k);
    }//end for
    getMaxColor(stackColor);
    System.out.println("==generateColor==end\n\n");
    return null;

    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    public class HighFive
        private void examineColors(BufferedImage image)
            long start = System.currentTimeMillis();
            int w = image.getWidth(), h = image.getHeight();
            int[] rgbs = image.getRGB(0,0,w,h,null,0,w);
            findHighFive(rgbs);
            long end = System.currentTimeMillis();
            System.out.println("total time = " + (end - start)/1000.0 + " seconds");
        private void findHighFive(int[] colors)
            int[] uniqueColors = getUniqueColors(colors);
            int[] colorCounts  = getColorCounts(uniqueColors, colors);
            int[] highFive     = getHighFive(colorCounts);
            // for each value of highFive find index in colorCounts
            // and use this index to find color code in uniqueColors
            for(int j = 0; j < highFive.length; j++)
                int index = findIndexInArray(colorCounts, highFive[j]);
                Color color = new Color(uniqueColors[index]);
                String s = color.toString();
                s = s.substring(s.indexOf("["));
                System.out.println("color " + s + "  occurs " +
                                    highFive[j] + " times");
        private int[] getUniqueColors(int[] colors)
            // collect unique colors
            int[] uniqueColors = new int[colors.length];
            int count = 0;
            for(int j = 0; j < colors.length; j++)
                if(isUnique(uniqueColors, colors[j]))
                    uniqueColors[count++] = colors[j];
            // trim uniqueColors
            int[] temp = new int[count];
            System.arraycopy(uniqueColors, 0, temp, 0, count);
            uniqueColors = temp;
            return uniqueColors;
        private int[] getColorCounts(int[] uniqueColors, int[] colors)
            // count the occurance of each unique color in colors
            int[] colorCounts = new int[uniqueColors.length];
            for(int j = 0; j < colors.length; j++)
                int index = findIndexInArray(uniqueColors, colors[j]);
                colorCounts[index]++;
            return colorCounts;
        private int[] getHighFive(int[] colorCounts)
            // find five highest values in colorCounts
            int[] highFive = new int[5];
            int count = 0;
            for(int j = 0; j < highFive.length; j++)
                int max = Integer.MIN_VALUE;
                for(int k = 0; k < colorCounts.length; k++)
                    if(colorCounts[k] > max)
                        if(isUnique(highFive, colorCounts[k]))
                            max = colorCounts[k];
                            highFive[count] = colorCounts[k];
                count++;
            return highFive;
        private boolean isUnique(int[] n, int target)
            for(int j = 0; j < n.length; j++)
                if(n[j] == target)
                    return false;
            return true;
        private int findIndexInArray(int[] n, int target)
            for(int j = 0; j < n.length; j++)
                if(n[j] == target)
                    return j;
            return -1;
        public static void main(String[] args) throws IOException
            String path = "images/cougar.jpg";
            Object o = HighFive.class.getResource(path);
            BufferedImage image = ImageIO.read(((URL)o).openStream());
            new HighFive().examineColors(image);
    }

  • Grabbing Pixels from an image into an array

    Hi,
    I am new to the image processing using java. I want to get the pixel values of an image and store it into an text file. Can anyone help me with this?
    This is what i've done yet? Is the values present in the text field the correct values of the pixels of the image.
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    import java.util.*;
    public class grabber extends Applet {
    private TextField tf;
    private TextArea ta;
    private Label status;
    private Canvas drawarea;
    private Image img=null;
    int ppmline=0;
    public void init() {
         setLayout(new GridLayout(1,2));
         Panel left=new Panel();
    left.setLayout(new BorderLayout());
    Panel topleft = new Panel();
    topleft.setLayout(new GridLayout(1, 4));
    topleft.add(tf=new TextField());
         Panel buttonsP = new Panel();
    buttonsP.add(new Button("Load GIF"));
         buttonsP.add(new Button("PPM Output"));
         topleft.add(buttonsP);
    left.add("North", topleft);
    left.add("Center", drawarea=new Canvas());
         left.add("South", status=new Label());
         add(left);               // left side of the applet.
         add(ta=new TextArea());          // right side.
         status.setText("See GIF files below.");
    public void paint(Graphics appletg) {
         Graphics g=drawarea.getGraphics();
         if (img != null) {
              g.drawImage(img, 0, 0, this);
              g.dispose();
    public boolean action(Event evt, Object arg) {
         String s=(String) arg;
         if(s.equals("Load GIF")) {
              img=getImage(getCodeBase(), tf.getText());
              repaint();
         else if (s.equals("PPM Output")) getPixs();
    return true;
    void getPixs() {
         int w=30, h=30;
         // PPM output starts.
         ta.setText("P3\n");
         ta.appendText(Integer.toString(w) + " " + Integer.toString(h) + "\n");
         ta.appendText("255\n");
         handlepixels(img, 0, 0, w, h);
    public void handlesinglepixel(int x, int y, int pixel) {
         // pixel is in RGB model. It is a 4-byte long integer.
         // It is converted into the string representation of PPM pixels.
         // ie. Hex 0x00102030 becomes "16 32 48"
         String s= Integer.toString((pixel & 0x00FF0000) >> 16) + " "
              + Integer.toString((pixel & 0x0000FF00) >> 8) + " "
              + Integer.toString(pixel & 0x000000FF) + " ";
    // If we use PPM RAW format, then we have to use ascii characters instead.
    //     char c[]= {(char) ((pixel & 0x00FF0000) >> 16),
    //          (char) ((pixel & 0x0000FF00) >> 8) ,
    //          (char) (pixel & 0x000000FF) };
    //     String s=new String(c);
         if (ppmline++>=3) {                // comment out if you use RAW format.
              ta.appendText(s + "\n");      // comment out if you use RAW format.
              ppmline=0;               // comment out if you use RAW format.
         } else                          // comment out if you use RAW format.
              ta.appendText(s);
    public void handlepixels(Image img, int x, int y, int w, int h) {
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    try {
    pg.grabPixels();
    } catch (InterruptedException e) {
    System.err.println("interrupted waiting for pixels!");
    return;
    if ((pg.status() & ImageObserver.ABORT) != 0) {
    System.err.println("image fetch aborted or errored");
    return;
    for (int j = 0; j < h; j++) {
    for (int i = 0; i < w; i++) {
    handlesinglepixel(x+i, y+j, pixels[j * w + i]);

    im not at home or id post some source code but first off
    if your going to write a file from a applet your going to
    have to get by permisions.
    so you should probably do this with a application
    it would be alot easier
    use toolkit.getdefaulttoolkit() to get the image then
    use the pixel graber class to read it into a array
    of the type you want string or char
    then just write it into a file each element of the array
    and when you want to read it just read it in with file reader
    you could probaly do a test run just write in each value as
    a string and put a comma between each value then use
    stringtokenizer to read it back in its less efficient but
    for a test run it would make things clearer
    sorry if its not much help

  • When backing up on time machine is get " The back up disk image'/volume/data/eric balnchard's Macbook.sparbundle"could not be accessed (error-1). what does it mean? it's a new time machine

    when backing up on time machine is get " The back up disk image'/volume/data/eric balnchard's Macbook.sparbundle"could not be accessed (error-1). what does it mean? it's a new time machine

    Expect to see this error again due to a bug in Lion (and Mountain Lion).
    See # C17 in Pondini's excellent support document below, or look over to the right of this web page under the heading of More Like This
    http://pondini.org/TM/Troubleshooting.html

Maybe you are looking for