Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners read an image in java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


amit kumar gupta
read an image in java
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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


Advertisement
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 maheshwari1986ashish@gmail.com
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 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
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. http://www.roseindia.net/jsp
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 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
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
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
 

 

 

DMCA.com