read an image in java

read an image in java

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;

import java.io.*;

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));
    System.setOut(out);
    BufferedImage image = readImage("C:/Untitled.jpg");               //Input Image file
    printAllARGBDetails(image);
}

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("--------------------------------------------");
    System.out.println("Image Scrambler");   
    System.out.println("Image Dimension: Height-" + height + ", Width-" + width);
    System.out.println("Total Pixels: " + (height * width));
    System.out.println("--------------------------------------------");
    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+"): ");
            System.out.print(idata);
            if(pix_num<total_pix)      
            {
                System.out.println("");
            }
            pix_num++;
        }
    }
}

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 = ImageIO.read(new 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
Advertisements
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]
image compression - Java Beginners
image compression  image compression in java coding
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
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 solution.my java code is given below. import java.io.File; 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
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
java image compression - Java Beginners
java image compression  image compression in java
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
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
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
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
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 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 effects - Java Beginners
image effects  hey can u help me in loadin an image file... that will show you image crop effect: import java.sql.*; import java.awt.... java.awt.image.FilteredImageSource; public class Upload extends JPanel { BufferedImage image; Image img
Display Image in Java
Display Image in Java     .... The image is read from the system by using ImageIO.read(File file) method... C:\image>java ShowImage Enter image name rajeshxml2.gif
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. http://www.roseindia.net/jsp
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
read complete file as string java
read complete file as string java  Hi, How I can read read complete file as string java? Thanks   Hi, You can do like this in one line: String fileContent = new String(Files.readAllBytes(Paths.get(fileName
Image Processing Java
://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-compression...Image Processing Java  Using This Code I Compressed A JPEG Image And the Original Size of the image is 257kb and The Compressed Image Size Is 27kb
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
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
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
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
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
Read data again - Java Beginners
Read data again  Hey, i want to ask again about how to read data... want this read to DB d00001;Operation;Finance;Finance Head;Kantor Pusat...;Operation;Finance;Finance Officer;Kantor Pusat; My question is:how to read
Read the value from XML in java
Read the value from XML in java  Hi, i have an XML with the following code. I need to get the path("D... the permissions on that file.So how can i read that value. This is little urgent
Read data again - Java Beginners
Read data again  sir, i still hav a problem,first your code will be change like this : in netbeans out message error 5. Can you help me again. My... = DriverManager.getConnection("jdbc:odbc:hyt","root","suprax"); //Read File Line By Line
Read data again - Java Beginners
Read data again  OK my problem some like my first question.First i...","root","suprax"); //Read File Line By Line while ((strLine = br.readLine..."); //Read File Line By Line while ((strLine = br.readLine()) != null
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... is the program to read a file in Java. import java.io.*; public class FileRead
image sending - Java Beginners
image sending  how to send an image from one computer(client) to other computer
how to convert string to image in java
how to convert string to image in java  how to convert string to image in java? I know we need to convert image to a byte array at some point in my application but do not know how to convert a image into byte string. Please
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 display - Java Beginners
; %><html><head><title>Retrive Image with jsp</title>...;--------------------------------------read for more information,http://www.roseindia.net/jsp/file_upload/Sinle
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting... found : java.awt.Image required: Image image = tool.getImage("D
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
image display in jsp - Java Beginners
image display in jsp  i uploaded the image and how can i print that image in next jsp page....  Hi friend, read for more information, http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
image embadding - Java Beginners
image embadding  sir how to put images in JFrame/JPanel  Hi... class DisplayImage extends JPanel{ private BufferedImage image; public DisplayImage() { try { image

Ads