Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 3rd, 2011, 02:52 PM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in reading image file

i am getting following errors when trying to read an image files pixel:
HTML Code:
F:\tm\final>java pixelcheck
1
2
no. of row is:-1
no. of col is:-1
Exception in thread "main" java.lang.NegativeArraySizeException
        at get3dimagepixelobj.get3ddata(get3dimagepixelobj.java:33)
        at pixelcheck.main(pixelcheck.java:15)
my image file is in f:\tm\final .
class file and image file is in same folder.


Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

class pixelcheck
{
  public static void main(String args[])
   {
     
	 get3dimagepixelobj j1=new get3dimagepixelobj();
     
	 
	 int[][][] datareturned = new int[400][][];//size of image file is           //400X299
	 String fname="f2.jpeg";
	 datareturned=j1.get3ddata(fname);
      for (int i=0;i<4 ;i++ )
      {
      System.out.println(datareturned[0][0][i]);
	  
	  }

   }
}
The other class get3dimagepixel obj is (few lines as it is very large):
Code:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

class pixeldetails
{
	int alpha;
	int red;
	int green;
	int blue;
	int area;
}
class get3dimagepixelobj extends pixeldetails
  {
    public int[][][] get3ddata(String imagefile)
	  {
	     //String imagefile;
         //Image rawimage=getImage(imagefile);
		 System.out.println("1");//to check the error
		 Image rawimage=Toolkit.getDefaultToolkit().getImage(imagefile);
	     		 System.out.println("2");//to check the error
		 int imagerows=rawimage.getHeight(null);
	               System.out.println("no. of row is:"+imagerows);//to check //the error
		 int imagecols=rawimage.getWidth(null);
				 System.out.println("no. of col is:"+imagecols);
		 // int imagecols=rawimage.getWidth(java.awt.image.ImageObserver);
	     int[] onedpix=new int[imagerows*imagecols];
         int[][][] threedpix=new int[imagerows][imagecols][4];
		 		 System.out.println("3.1");





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in reading php file iswariyas Beginning PHP 2 March 13th, 2010 08:56 PM
Reading Strings from Text File problem gian.sobhani C# 2005 1 August 31st, 2009 08:17 AM
Problem reading XML file from Northwind Database (SQL 2005) jujiro_eb XML 4 June 5th, 2009 01:57 PM
Problem in reading some part of a file denzil_cactus Perl 1 June 29th, 2007 09:29 AM
Problem with reading BAT file rhysduk VB How-To 0 January 12th, 2005 09:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.