Jucer fails to create image component


#1

Hi there
I wanted to make use of the Jucer in order to create a simple image component. This means a component that holds nothing but a simple JPG image. I was delighted to see the Jucer is actually transforming the JPG into numbers. Here is the code.

Header

[code]#ifndef JUCER_HEADER_LOGOIMAGECOMPONENT_LOGOIMAGECOMPONENT_CD091C2B
#define JUCER_HEADER_LOGOIMAGECOMPONENT_LOGOIMAGECOMPONENT_CD091C2B

#include “juce.h”

class LogoImageComponent : public Component
{
public:
//==============================================================================
LogoImageComponent ();
~LogoImageComponent();

//==============================================================================
//[UserMethods]     -- You can add your own custom methods in this section.
//[/UserMethods]

void paint (Graphics& g);
void resized();

// Binary resources:
static const char* logo_jpg;
static const int logo_jpgSize;

//==============================================================================
juce_UseDebuggingNewOperator

private:
//[UserVariables] – You can add your own custom variables in this section.
//[/UserVariables]

//==============================================================================
Drawable* drawable1;

//==============================================================================
// (prevent copy constructor and operator= being generated..)
LogoImageComponent (const LogoImageComponent&);
const LogoImageComponent& operator= (const LogoImageComponent&);

};
#endif[/code]

Method bodies (reduced)

[code]/*

This is an automatically generated file created by the Jucer!
[…]
Jucer version: 1.12

*/

//[Headers] You can add your own extra header files here…
//[/Headers]

#include “LogoImageComponent.h”

//[MiscUserDefs] You can add your own user definitions and misc code here…
//[/MiscUserDefs]

//==============================================================================
LogoImageComponent::LogoImageComponent ()
{
drawable1 = Drawable::createFromImageData (logo_jpg, logo_jpgSize);

//[UserPreSize]
//[/UserPreSize]

setSize (1015, 260);

//[Constructor] You can add your own custom stuff here..
//[/Constructor]

}

LogoImageComponent::~LogoImageComponent()
{
//[Destructor_pre]. You can add your own custom destruction code here…
//[/Destructor_pre]

deleteAndZero (drawable1);

//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]

}

//==============================================================================
void LogoImageComponent::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here…
//[/UserPrePaint]

g.fillAll (Colours::white);

g.setColour (Colours::black);
jassert (drawable1 != 0);
if (drawable1 != 0)
    drawable1->drawWithin (g, 0, 0, 1015, 260,
                           RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize);

//[UserPaint] Add your own custom painting code here..
//[/UserPaint]

}

void LogoImageComponent::resized()
{
//[UserResized] Add your own custom resize handling here…
//[/UserResized]
}
//==============================================================================
#if 0
/* – Jucer information section –

This is where the Jucer puts all of its metadata, so don't change anything in here!

BEGIN_JUCER_METADATA

<JUCER_COMPONENT documentType=“Component” className=“LogoImageComponent” componentName="“
parentClasses=“public Component” constructorParams=”" variableInitialisers=""
snapPixels=“8” snapActive=“1” snapShown=“1” overlayOpacity="0.330000013"
fixedSize=“1” initialWidth=“1015” initialHeight=“260”>



</JUCER_COMPONENT>

END_JUCER_METADATA
*/
#endif

//==============================================================================
// Binary resources - be careful not to edit any of these sections!

// JUCER_RESOURCE: logo_jpg, 56238, "…/Logo.jpg"
static const unsigned char resource_LogoImageComponent_logo_jpg[] = { 255,216,255,225,11,186,69,120,105,102,0,0,77,77,0,42,0,0,0,8,0,7,1,18,0,3,0,0,0,1,0,1,0,0,1,26,0,5,0,0,0,1,0,0,0,98,1,27,0, […]
const char* LogoImageComponent::logo_jpg = (const char*) resource_LogoImageComponent_logo_jpg;
const int LogoImageComponent::logo_jpgSize = 56238;
[/code]

Then I instantiate this class.

LogoImageComponent* logoImageComponent = new LogoImageComponent(); this->addAndMakeVisible(logoImageComponent);

Alas, it does throw an jassert at:

void LogoImageComponent::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here…
//[/UserPrePaint]

g.fillAll (Colours::white);

g.setColour (Colours::black);
[b]jassert (drawable1 != 0);[/b]
if (drawable1 != 0)
    drawable1->drawWithin (g, 0, 0, 1015, 260,
                           RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize);

//[UserPaint] Add your own custom painting code here..
//[/UserPaint]

}

Since I didn’t do coding by myself I figure this a Jucer problem.

Any ideas?


#2

Looks like it’s failing to load the image for some reason. What version of juce are you using?


#3

The Jucer 1.12
Juce 1.44

This fails

LogoImageComponent::LogoImageComponent () { drawable1 = Drawable::createFromImageData (fender_logo_jpg, fender_logo_jpgSize);
I can hardly change the Juce version. It’s a project I inherited from another person who has given up on it. Since the code is partly beyond a state of being repairable I am very reluctant to touch core settings like libs.


#4

Ah, well sorry, I haven’t time to spend chasing bugs that were probably fixed several years ago!


#5

I see. Thanks anyway.


#6

You could probably fix it yourself if you need to - it’s unlikely to be anything complicated.


#7

Now I managed to update to Juce 1.51. The problem remains! Does that qualify for some requests? I have no clue as where to start.

One hint. When creating the component with The Jucer, it displayed ‘image missing’ though it was successfully loaded and tranformed into code. See attached screenshot.


#8

Yes, you certainly get help for up-to-date bugs!

If it doesn’t display the file, then the jpeg decoder can’t understand the file. Sure, it’ll add the bytes to the binary, but that doesn’t mean it can load them. Maybe try re-saving the jpeg using an image editor, in case it’s written in an unusual format?


#9

The sun is rising. I re-saved using IrfanView and this time it worked. Many thanks!!