Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT ImageData -- How to obtain number of channels?(SWT ImageData -- How to obtain number of channels?)
SWT ImageData -- How to obtain number of channels? [message #527944] Sat, 17 April 2010 07:55 Go to next message
JIA Pei is currently offline JIA PeiFriend
Messages: 49
Registered: September 2009
Member


Hi, all:

I'm wondering how I can obtain the number of channels for a loaded image, using SWT technology.

Let's have a look at the following website first.
http://www.eclipse.org/articles/Article-SWT-images/graphics- resources.html#ImageData

By using
ImageData ideaImageData = new ImageData(
    getClass().getResourceAsStream("Idea.jpg"));


we loaded an image and stored in
ImageData ideaImageDat


In Eclipse' documentation at
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/reference/api/overview-summary.html

Nothing can be found to tell "number of image channels", in the class "ImageData".

What I would like to find is something like a function getNbOfChannels();

If the loaded image "idea.jpg" is a color image, then, the function returns 3
If it is a gray image, then, the function returns 1.


Can anybody help to give me a hand ?

Cheers
JIA Pei





[Updated on: Sat, 17 April 2010 07:58]

Report message to a moderator

Re: SWT ImageData -- How to obtain number of channels? [message #527967 is a reply to message #527944] Sat, 17 April 2010 16:06 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf EbertFriend
Messages: 168
Registered: July 2009
Senior Member
Hi JIA Pei,

> I'm wondering how I can obtain the number of channels for a loaded
> image, using SWT technology.

see ImageData#depth.

- Ralf

--
Learn how to contribute to Eclipse here: http://eclipse.org/contribute/
Read my Blog here: http://www.ralfebert.de/blog/
Follow me on Twitter here: http://twitter.com/ralfebert/
Re: SWT ImageData -- How to obtain number of channels? [message #527970 is a reply to message #527967] Sat, 17 April 2010 16:52 Go to previous message
JIA Pei is currently offline JIA PeiFriend
Messages: 49
Registered: September 2009
Member


Hi, Dear Ralf:

Thank you very much for you prompt reply !!

Now, I'm using

int NbOfChannels	= iImg.bytesPerLine/iImg.width;


but, I've got no idea whether it's correct or not.

As for depth, in my case, it's always 8. (that's why I think "bytesPerLine" might be able to work)
But, that only relates to number of bits used for a single channel of a pixel.
Namely, if I'm using 3 channels for a pixel, that will cost 3*8=24 bits.

In this case:
depth = 8
NbOfChannels=3


How do you think of it? ^_^

Thank you very much.

Best Regards
JIA


Ralf Ebert wrote on Sat, 17 April 2010 12:06
Hi JIA Pei,

> I'm wondering how I can obtain the number of channels for a loaded
> image, using SWT technology.

see ImageData#depth.

- Ralf

--
Learn how to contribute to Eclipse here: http://eclipse.org/contribute/
Read my Blog here: http://www.ralfebert.de/blog/
Follow me on Twitter here: http://twitter.com/ralfebert/

Previous Topic:browser page loading
Next Topic:TreeItem setBackGround() not working....
Goto Forum:
  


Current Time: Sun Aug 18 03:15:59 GMT 2019

Powered by FUDForum. Page generated in 0.03032 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top