Hi,
I thought a SingleChannel image behaves like an image with only an alpha channel, or am I understanding this wrong? I’m having the following issues, on Windows 10:
-
Using a
ColourGradient
doesn’t seem to work, the commented out block draws something, but it isn’t a circular gradient. -
And painting a resized version of the image with smoothing produces artefacts. See the paint method and resulting image below.
void paint(Graphics &g) override
{
g.fillAll(Colours::yellow);
// image with simple diagonal gradient
int w = 10, h = 10;
Image monochrome(Image::SingleChannel, w, h, false);
{
Image::BitmapData bm(monochrome, Image::BitmapData::writeOnly);
for (int y = 0; y < h; ++y)
{
uint8 *line = bm.getLinePointer(y);
for (int x = 0; x < w; ++x)
{
line[x] = (uint8)jlimit(0, 255, (x+y*3) * 50 - 900);
}
}
}
// because this doesn't draw a circular gradient...
//{
// Graphics ig(monochrome);
// ColourGradient gradient(Colours::transparentBlack, 5.f, 5.f, Colours::black, 11.f, 5.f, true);
// ig.setGradientFill(gradient);
// ig.fillAll();
//}
// use black fill:
g.setColour(Colours::black);
// actual size
g.drawImageWithin(monochrome, 0, 0, w, h, RectanglePlacement::doNotResize, true);
// with low quality resizing
g.saveState();
g.setImageResamplingQuality(Graphics::lowResamplingQuality);
g.drawImageWithin(monochrome, 15, 0, 200, 200, RectanglePlacement::stretchToFit, true);
g.restoreState();
// with default quality resizing
g.drawImageWithin(monochrome, 220, 0, 200, 200, RectanglePlacement::stretchToFit, true);
}