Thu Oct 23, 2008 1:06 am
Thu Oct 23, 2008 1:07 am
public static void image(){
try {
File f=new File("e:\\asd\\21.bmp");
//read the image into Buffer
BufferedImage imgb=ImageIO.read(f);
//get the image width + height
int imageW=imgb.getWidth();
int imageH=imgb.getHeight();
//define ONE dimsneion arry to read the image into
int imgArr[]=new int[imageW*imageH];
//read all the the pixels info into the array
imgb.getRGB(0,0,imageW,imageH,imgArr,0,imageW);
//NOTE: each element in the array will present: (all in Hex
values)
//1- Transperancy of the color
//2- Red color
//3- Green color
//4- Blue color
//
//example if the color in the image was Lime (between green
and yellow)
//its RGB is (186,255,0)
//the result will look like: FFBAFF00 , where:
//FF mean full opaque
//BA is 186
//FF is 255
//00 is 0
//this loop will show each pixel correspondent Hex value
String out="";
for (int i = 0; i < imgArr.length; i++) {
if (i % imageW ==0) out+="\n";
out+=Integer.toHexString(imgArr[i]).toUpperCase() + "
";
}
javax.swing.JOptionPane.showMessageDialog(null,out);
//the follwoing code fills the array in 2D array
//convert to 2D array
int img2D[][]=new int[imageW][imageH];
for (int x = 0; x < imageW; x++) {
for (int y = 0; y < imageH; y++) {
img2D[x][y]=imgArr[y*imageW+x];
}
}
//printing the new array (should be same as the previous
time)
out="";
for (int y = 0; y < imageH; y++) {
for (int x = 0; x < imageW; x++) {
out+=Integer.toHexString(img2D[x][y]) + " ";
}
out+="\n";
}
javax.swing.JOptionPane.showMessageDialog(null,out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Fri Apr 29, 2011 12:55 pm
String filename = File.separator+"tmp";
JFileChooser fileChooser = new JFileChooser(new File(filename));
fileChooser.showOpenDialog(mainPanel);
File file = fileChooser.getSelectedFile();
try {
BufferedImage imBuf = ImageIO.read(file);
int imgW = imBuf.getWidth();
int imgH = imBuf.getHeight();
int imgAr[] = new int[imgW*imgH];
//Bufferede img nin 0-0 dan w - h ye kadar olan kısmın rgb degerlerini alıp
// imgAr dizisine döndürür;
imBuf.getRGB(0, 0, imgW, imgH, imgAr, 0, imgW);
//NOTE:
//Dizideki elemanların herbir Hex degerleri karsılıgı
//1- Transparanlık //2- Red //3- Green //4- Blue
String out="Naber ibrahim ?";
out +=" \n"+Integer.toString(imgAr[381]);
JOptionPane.showMessageDialog(null, out);
//imgAr[] de tek boyutlu hali bulunuyor dizinin;
//ConvertTo 2D dimension
int img2D[][] = new int [imgH][imgW];
// row/col 447 382
//My image Height & Width
for(int i=0; i<imgH; i++)
for(int j=0; j<imgW; j++){
img2D[i][j] = imgAr[j+imgW*i];
}
out += " \n"+Integer.toString(img2D[0][381]);
JOptionPane.showMessageDialog(null, out);
} catch (IOException ex) {
Logger.getLogger(ImageProcessingView.class.getName()).log(Level.SEVERE, null, ex);
}
Mon Jan 21, 2013 9:42 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.