Share on Google+Share on Google+

amit kumar gupta
read an image in java
1 Answer(s)      6 years and 5 months ago
Posted in : Java Beginners

qns: how we can read an image tell me about its code?


View Answers

February 7, 2013 at 12:26 PM

import java.awt.image.*;

import javax.imageio.ImageIO;


public class Converter


public static void main(String[] args) throws FileNotFoundException, IOException
    File output_file=new File("C:/pixels.txt");                   //Output Text file
    PrintStream out=new PrintStream(new FileOutputStream(output_file));
    BufferedImage image = readImage("C:/Untitled.jpg");               //Input Image file

public static void printAllARGBDetails(BufferedImage image)
    int width = image.getWidth();
    int height = image.getHeight();
    int pix_num=1;
    int total_pix=width*height;
    System.out.println("Image Scrambler");   
    System.out.println("Image Dimension: Height-" + height + ", Width-" + width);
    System.out.println("Total Pixels: " + (height * width));
    for (int i = 0; i < width; i++)
        for (int j = 0; j < height; j++)
            int pixel = image.getRGB(i, j);
            String idata=(getARGBPixelData(pixel));
            System.out.print("Pixel ("+i+","+j+"): ");

public static String getARGBPixelData(int pixel)
    String ARGBvalue="";
    int alpha = (pixel >> 24) & 0x000000FF;
    int red = (pixel >> 16) & 0x000000FF;
    int green = (pixel >>8 ) & 0x000000FF;
    int blue = (pixel) & 0x000000FF;
    ARGBvalue = alpha + " " + red + " " + green + " " + blue;
    return ARGBvalue;

public static BufferedImage readImage(String fileLocation) throws IOException
    BufferedImage img = null;
    img = File(fileLocation));
    return img;


Related Tutorials/Questions & Answers:
read an image in java
read an image in java  qns: how we can read an image tell me about its code
read image
read image  java code to read an image in the form of an array.  ... ReadImageInArray { public static int[] getImagePixels(BufferedImage image...() * image.getHeight()]; try { grabber = new PixelGrabber(image, 0, 0
Read content for JPEG image File in Java - Java Beginners
Read content for JPEG image File in Java  How to Read content for JPEG image File in Java? or Extract text from JPEG image File in Java
JME image read
JME image read  how to display more then one image in jme after reading from nokia 6303 phone. reply me at [email protected]
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
How to read loops in Java
How to read loops in Java  Example that explains how to read loop in Java
Java read binary file
Java read binary file  I want Java read binary file example code that is easy to read and learn. Thanks   Hi, Please see the code at Reading binary file into byte array in Java. Thanks   Hi, There is many
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
image compression - Java Beginners
image compression  image compression in java coding
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know...Read XML using Java  Hi All, Good Morning, I have been working as a Manual Test engineer for last 4 years. Now i started learning java
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have only one element with multiple attributes with same tag name. here is my file... a java code is given below. import; import
READ DATA - Java Beginners
READ DATA  i still don't understand, i have a data like this : d00002;Marketing;Finance; d00002;Marketing;Acct-Tax; d00002;Marketing;Acct-Tax... = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line
java image compression - Java Beginners
java image compression  image compression in java
read xml using java
read xml using java  <p>to read multiple attributes and elements from xml in an order.... ex :component name="csl"\layerinterfacefile="poo.c...;   Please visit the following link: Read XML data
Read from a window - Java Beginners
Read from a window  HI, I need to open a website and read the content from the site using Java script. Please suggest. Thanks
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
image - Java Beginners
image  how to identify the watermarked image? or how to convert the watermarked image into original image? can you send that corresponding java code
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
To read a excel with chart - Java Beginners
To read a excel with chart   Hi, I need to read the data in an excel which is in chart format using java. when I directly change the extention of excel file to CSV i am not getting the data in the chart.Please help me
image insert - Java Beginners
image insert  i browsed the image by clicking d browse button.if i press submit button means d image automatically stored in db.then i have 2 retrieve d image separately...................... Untitled Document
Java read lines from file
Java read lines from file  Any code example related to Java read... of reading file line by line in Java. Can any one share me the code for reading java file line by line. My file is very big around 6.5GB so it's not possible
Converting HTML to image - Java Beginners
Converting HTML to image   Is it possible to convert html to image with java code ?   Hi friend, Please give the problem in details for complete solution. For read more information : http
image comparison - Java Beginners
image comparison  hi all, pls help me to compare 2 images(in pixel and pattern) using jsp...the image pixels are in a xml file...  Hi friend, Read for more information.
Image using Java coding
Image using Java coding  Hai, Display image in pdf file using Java coding through Xsl file.. Please help me.. xsl file generate the pdf file
Java Image Browsing Applet
Java Image Browsing Applet  Hi. I want to create an applet which is embedded in html page which display image by browsing the files in the computers hard disk... Please help me out
image upload in java
image upload in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog is open
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog
Java file read write operation
Java file read write operation  how to read and write the data from..."); oos.writeInt(8000); oos.writeObject("Ankit"); oos.writeObject("Java..."+sal1); for complete tutorial you can follow this link Java ObjectOutputStream
How to Read a File in Java
How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get... can be very inefficient. Example Here is the program to read a file in Java
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null