Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes problem in checking the dimensions of an image. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem in checking the dimensions of an image." Watch "problem in checking the dimensions of an image." New topic
Author

problem in checking the dimensions of an image.

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
im doing validations in java code for image upload..im unable to get validated i.e.,if two files are entered it should check for the dimensions.i m unable to code how to check for the dimensions...can anyone help me out...here is the code...


thanks,
madhu.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

What are classes ImageContentArray, ContentResponse and ImageContentData?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
it takes ArrayList in ImageContentArray and ImageContentData and in ContentResponse takes whether the entered userid,key and access..i need is i need to upload image file..if i upload image file it should check for the 'dimensions,filetype'..if i enter the same dimensions then it should through an error...im not getting any idea how to validate the fields...can you help me out.

thanks,
madhu.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Since I know absolutely nothing of your ImageContentData I cannot tell you how to read the dimensions of an image that is apparently contained in it. TellTheDetails.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
here is my code
1)ImageContentData.java


2)validation.java

can you check it and help me how to code..
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Posting the code of class ImageContentArray does not help us understand how class ImageContentData works.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
then tell me what should be required..i'll post
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You should respond to this post:
Rob Prime wrote:Since I know absolutely nothing of your ImageContentData I cannot tell you how to read the dimensions of an image that is apparently contained in it. TellTheDetails.

The response should make it clear how images are stored in class ImageContentData; we may then be able to suggest how to obtain image dimensions.
Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
Hey Madhuri,

Lester and Rob are very much right in their own way. Your question is very specific to a class which would not make sense unless the reader has some background of that.

Anyways...what I could make out on my own is, you have two images and you want to compare them for their height and width.
If I my udnerstanding of your probolem is correct you should see java.awt.Image class.


Pl correct my if I got you wrong.


There are only 10 types of people in the world: those who understand ternary, those who don't, and those who mistake it for binary.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
im doing application in which im uploading images for suppose im uploading 2 images at a time.I need to check the following conditions
1)check if uploaded images had Duplicate File Name...if i has same File Name..then it should throw an error.
2)check if uploaded images had Duplicate Dimensions...if i has same File Name..then it should throw an error.
and i coded in the following java files
1)contentProp

2)contentResponse.java

3)contentValidation.java

i m not getting idea how to check the conditions for validations in isValidImageContent() method...can any one help me out..
Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
Dear Madhuri...posting entire code will only make it messy widout much/no description.
e.g. your ContentProperties does not make any sense to me.

you mentioned you want to validate image name and dimension but I dont see that in the code posted. Moreover, I am yet to understand your problem.

Please go through the link provided by Rob TellTheDetails.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Abhishk,
i need to code in

in isValidImageContent() method in validations.java file..i m not getting idea how to code for validations of image upload...can you suggest me how to code..i had mentioned in //need to do validations comment in the code.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Why are you posting code that has nothing to do with image dimensions (which you said was the problem)? Why are you not posting the code of the ImageContentData class?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
here is the ImageContentData.java
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
So you have the image contents as a byte[]; that's a good start. There was a discussion about a class called ImageInfo that could figure out image dimensions without knowing which format the image was in. It looks like that class needs an InputStream, which you could get from the byte[] by using a ByteArrayInputStream.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Lester,
i got what you suggested..im developing mobile application.In which user can upload image from internet to his mobile...im writing code if user uploads 2images that should validated...i need to write in for loop..im not getting idea how to check 2 images are same or not...that is my problem..can you suggest me how to code it..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How to check if two images are the same? That's a completely different thing than comparing a filename and dimensions. Which is it?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi David,
i need to compare a filename and dimensions for the uploaded image...i had wrote wrongly..here i had done some coding..can you check and provide me solution..i searched in net but im not getting any info...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://www.coderanch.com/t/506301/java/java/Image-Dimensions-Delete-as-Needed
http://www.coderanch.com/t/370213/java/java/Image-Dimensions
http://forums.sun.com/thread.jspa?threadID=214570
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
i had done some validation in uploading my image for my mobile application...im unable to check whether the file is uploaded or not...i used System.out.println statement for verification..but im not getting...can anyone check it and provide me the solution..here is the code and im using console application..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i used contentResponse for checking purpose...im not getting..any help..
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
madhuri kunchala wrote:
Arrays.equals(imageContentData.getFileBytes(), imageContentData.getFileBytes())
imageContentData.getType().equals(imageContentData.getType())
imageContentData.equals(imageContentData)
imageContentData.getDimesions().equals(imageContentData.getDimesions())

These conditions will always evaluate to true, so they're most likely not what you intended to do.

Also, having "imageContentData.getFileBytes() != null" trigger the "Duplicate File Name" case looks suspicious; did you mean to use "&&" instead of "||"?

Lastly, "imageContentData.getType().trim()" (and the following ones) will never be null, so the check for null is bogus. "imageContentData.getType()", however, could conceivably be null, in which case the "trim()" call would throw an exception. You probably want to check "imageContentData.getType() != null" instead.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Lester,
i had done modifications what you had suggested..eventhough im not getting the System.out.println("hello"); is not getting printed...here is the modified code...
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
This looks suspicious: "imageContentData.getFileBytes() == null"

All the "equals" comparisons still don't make sense.

And just to be sure: imageContentDatas contains at least one item, and validContentB is true, yes?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
validContentB is true...can you suggest where i need to change the code..
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Have you addressed the first point of my previous post? It's crucial, as is imageContentDatas not being empty.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k..the ImageContentDatas is an ArrayList and it cant be empty...then how to check or validate the fileds different methods that are checked by the ImageContentData
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Lester Burnham wrote:Have you addressed the first point of my previous post? It's crucial, as is imageContentDatas not being empty.

Have you?

madhuri kunchala wrote:..the ImageContentDatas is an ArrayList and it cant be empty

If it can't be empty, then why is there code that checks whether it's empty and creates an error message if it is?

I'm getting the idea that you're not going about this very methodically. At this point I think it would be faster if you inserted System.out.println statements between each two lines of code, and print the values of all variables. Then you'll know how the code behaves and why. (It may be easier to do this using a debugger in your IDE, if you're using one.)
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k..i'll check it and i'll find out where it goes wrong..
 
 
subject: problem in checking the dimensions of an image.