size of image file

hi. I want to ask about: how can we get the size of an image file (in Byte/kByte)? Because i want to put it in the edit box/text. thanks.

Answers (2)

Walter Roberson
Walter Roberson on 6 Mar 2012

0 votes

Use dir() and look at the "size" field that is returned; that will be in bytes.

4 Comments

Ju
Ju on 6 Mar 2012
Sorry, i don't get it by using dir().
i make an application using GUI matlab. When i press button, the textbox will show the size.
Can you tell me another option?
The other options are much worse to write, and are not portable.
fileinfo = dir(ImageFileName);
filesize = fileinfo(1).size;
Ju
Ju on 6 Mar 2012
sorry for bothering you again.
but there's an error, it says: "dir is not defined for 'uint8' input"
what does it mean? and how can i fix it?
thanks a lot.
Jan
Jan on 6 Mar 2012
@Walter, a small typo: filesize = fileinfo(1).bytes, not ".size".

Sign in to comment.

Jan
Jan on 6 Mar 2012
"dir is not defined for 'uint8' input"
This mean that you call DIR with an UINT8 variable like:
a = uint8(rand(10));
b = dir(a);
I assume you read an image file into a variable and use this variable instead of the filename afterwards.
A general recommendation: It is efficient to post the code, which causes the problem, and the complete error message. Then assisting is easier and efficient.

1 Comment

Ju
Ju on 6 Mar 2012
this is my code:
[fileName,pathName] = uigetfile({'*.gif','Animated GIF FIle{*.gif}'},'Open File');
[imageFile map] = imread(fullfile(pathName,fileName),'frames','all');
temp = imageFile;
fileInfo = dir(temp);
fileSize = fileInfo(1).size;
set(handles.edit1,'String',num2str(fileSize));
can you tell me what's wrong with that?

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Asked:

Ju
on 6 Mar 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!