Problem with Single Channel Image


#1

Hy everybody!

I have a problem with single channel images. I sucessfully create a single channel image and load with data. But when i want to show this image with g.drawImage function, i don’t see anything. I don’t know what is the problem.
How the Juce handle the single channel images? Any idea?

Thanks for the answers.


#2

Hmm, they should be drawn using the current colour… Which OS is this? Got a piece of sample code that fails?

(But before I look into this, please check that it really is a problem with the image type by trying the same thing with ARGB. You could just be drawing it off-screen or something)


#3

The OS is Windows 7, with visual C++ 2008 and Juce 1.50.

When i use Image::ARGB as pixel format, it works well.
I create a single channel image:
juce::Image* testImage = new Image(juce::Image::SingleChannel, imageProcessor->getImageWidth(),imageProcessor->getImageHeight(), true);

And after that i dont really know how can i load this image with simple uint8 values.

I tried to create bitmapdata as:
Image::BitmapData bd(*testImage , 0, 0, testImage ->getWidth(), testImage ->getHeight(), true);

and after that i doing this
for(int i = 0; i < testImage ->getWidth() * testImage ->getHeight(); ++i)
bd.data[i] = 128;
it should be a gray color image in single channel.
Propably this is the problem, because the drawimgae function works well if i use ARGB or RGB pixel format.
Could you explain, how the juce handle the single channel pixelformat? I didn’t found to much about that in the refernce.

Thank you.


#4

There’s your problem.


#5

So juce 1.50 couldn’t handle single channel image format. I see.

The new version of juce handle this? I think yes. One more question.
If i use the latest version, the imge fill, what i wrote to set pixel values, is it correct?


#6

Well, the BitmapData class has changed since then, but essentially, yes.


#7

[quote=“Arpad”]I have a problem with single channel images. I sucessfully create a single channel image and load with data. But when i want to show this image with g.drawImage function, i don’t see anything. I don’t know what is the problem.
How the Juce handle the single channel images? Any idea?[/quote]

The only meaningful way to “display” a single channel image is to fill with the current brush. Typically a solid color. Set the brush then call Graphics::drawImageAt with fillAlphaChannelWithCurrentBrush set to true.

Of course you should be on the most recent JUCE.