I can’t seem to figure out what I’m doing incorrectly. I have an app that loads images and displays them in a new window. Sometimes, the images show up the correct size, other times they are larger. I’ve been through a ton of debugging, and have checked that that image dimensions, after being loaded into an Image object in JUCE, are the same as their actual dimensions, and they are always the same, but the image doesn’t display correctly, almost as if I have a resolution or scaling option enabled somewhere. I’ve already checked to make sure the getDesktopScalingFactor() and it returns 1 every time.
Here’s my loading code:
Here’s the class for the new window, which was almost a direct copy and paste of the JUCE Plugin new window code:
class BasicWindow : public DocumentWindow
{
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BasicWindow)
public:
BasicWindow (const String& name, Colour backgroundColour, int buttonsNeeded)
: DocumentWindow (name, backgroundColour, buttonsNeeded)
{
}
void closeButtonPressed() override
{
delete this;
}
};
Here’s my “display image” code:
void TrackNotesAudioProcessorEditor::createImageWindow(SafePointer<BasicWindow> &basicWindowPtr, Image &image, File &imagePath)
{
// Don't allow multiple copies of this window to be made
if(basicWindowPtr == NULL)
{
basicWindowPtr = new BasicWindow(imagePath.getFileNameWithoutExtension(), Colours::grey, DocumentWindow::allButtons);
basicWindowPtr->setUsingNativeTitleBar(true);
basicWindowPtr->setContentOwned(new ImageWindow(image), true);
basicWindowPtr->setAlwaysOnTop(true);
basicWindowPtr->centreWithSize(basicWindowPtr->getWidth(), basicWindowPtr->getHeight());
basicWindowPtr->setVisible(true);
}
And here’s my paint code in the new window that pops up:
void ImageWindow::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]
g.fillAll (Colour (0xff373737));
g.setColour (Colours::white);
g.setFont (Font (15.00f, Font::plain).withTypefaceStyle ("Regular"));
g.drawText (TRANS("Please Load an Image"),
0, 0, 200, 200,
Justification::centred, true);
//[UserPaint] Add your own custom painting code here..
g.drawImageAt(image, 0, 0, false);
//[/UserPaint]
}
This may be way too much code to post, but I’m not sure how else to make the problem, or code, any shorter to explain. If an image isn’t loaded into the application, the window just opens up at 200x200 and displays the message “Please Load an Image.” Otherwise, the window is loaded and it fills the window… only sometimes the images are larger than normal. I cannot figure out why.