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?