Loading jpgs, bmps


#1

Hi, i’ve problems loading jpgs and bmps. I’m pretty confussed with ImageFileFormat, JPEGImageFormat, Image, ImageCache and Drawable image… I don’t achieve load a single image!

Please, would you mind write and small code how should I load a simple c:\image.jpg file to be showed in a drawable image class?

Thanks you!!


#2

You’d just call Image::loadFromFile (“c:\image.jpg”)… I can’t really see how I could possibly have made that any easier! If you grep for “Image::loadFromFile”, there must be plenty of examples in the demo code.

To get it into a drawable, just create a new DrawableImage, and call its setImage() method… Again, if you can think of any way I could make it more obvious, please let me know!


#3

:S

I cannot see the method “loadFromFile” (or similar) in Image class:
http://www.rawmaterialsoftware.com/juce/api/classImage.html

Sorry by my ignorance :oops:

edit: take a look to this code:


#4

Oh, sorry… I meant ImageFileFormat::loadFrom() (doh!)
http://www.rawmaterialsoftware.com/juce/api/classImageFileFormat.html


#5

BTW, createFromImageFile is a static method that returns the created object, and BMPs aren’t supported anyway: please move to PNGs and let the awful BMP format die like it should have done 10 years ago…


#6

Thanks jules, i tried it, but it doesn’t work. I used a PNG but nothing :frowning:


	File temp(T("D:\\Dibujo.png"));

	fondoPantalla = new DrawableImage();

	Image* p_ima = ImageFileFormat::loadFrom(temp);
	Image ima = *p_ima;
	fondoPantalla->setImage(ima);

The image isn’t showed. I continue looking for it in forums and docs…


#7

However I can see the image with a ImageButton :shock: , but I cannot see it if I rescale images (second argument = true)

	Image* p_ima = ImageFileFormat::loadFrom(temp);
	Image ima = *p_ima;
	fondoPantalla->setImage(ima);
	
	Image* p_ima2 = ImageCache::getFromFile(temp);
	Image ima2 = *p_ima2;
	fondoPantalla->setImage(ima2);
	
	iboton = new ImageButton("imagen");
	addAndMakeVisible(iboton);
	iboton->setBounds(0,0,200,200);
	iboton->setImages(false, false, false, p_ima2, 0, Colours::blanchedalmond, p_ima, 0, Colours::antiquewhite, p_ima2, 0, Colours::aliceblue);

The idea is that I want use a resizable background image with object in it. I continue investigating…


#8

Why not just use the jucer? It generates all this code for you. Or at least use the jucer to generate example code for you to see how to use it…


#9

Yes, it’s a good idea, but I need that user can choose the background image. Jucer include the default image in the project, and it cannot be resizable!

Any clue?

Thank for your support :slight_smile:


#10

I DID IT!!!

THANKS!!!

I didn’t know that I have to use g.drawImage(…) in component’s paint method. Thanks jules!!


#11

I feel very confused. Why does juce not support bmp file?

Although it has some disadvantage, but it still is used normally, I think it’s the basic feture for the image issue.