SVG file as Image in drawImage of graphics

Hello Juce friends,

I have drawn svg images using Drawable. I need SVG image In juce::Image to draw into Graphics::drawImage().
I tried with juce::ImageCache::getFromFile(file), but it is not working, I also tried juce::ImageFileFormat ::loadFrom(file).
None worked, it does not give error but it does not draw image also. both works well when i use PNG image.

How can i put svg image into graphics::drawImage() method as image, that is all i need to do. please help

Thank Friends…

Image myImage (Image::ARGB, width, height, true); Graphics g (myImage); svgDrawable->drawWithin (g, ..etc);

1 Like

Actually, since a Drawable is a component, you could probably use Component::createComponentSnapshot too, although I’m not sure if the size would be correct.

Hey Jules, really appreciate your quick reply…

is it ScopedPointer svgDrawable;
svgDrawable->drawWithin (g, …etc);

I get it, thanks it helped lot, first i misinterpreted, sorry. But i get it well now.

Hi Jules,
I have obeyed the code structure you had given me… And it is working fine as well… But in some .svg images I’m having some problems displaying the image as it is only showing inside half of the total width and the height is going a little outside from the dimensions… Are you aware of any such cases ? Thanks so much…

[quote=“acn”]Hi Jules,
I have obeyed the code structure you had given me… And it is working fine as well… But in some .svg images I’m having some problems displaying the image as it is only showing inside half of the total width and the height is going a little outside from the dimensions… Are you aware of any such cases ? Thanks so much…[/quote]

Well, I’m aware that there are probably lots of bits of the (very large) SVG spec that aren’t implemented in my lightweight SVG parser. If you want to send me any files that seem to show a problem, please email them over, or more helpfully, have a look inside and try to figure out which elements my parser isn’t handling.

I had a look at your SVG and can’t see a problem - the picture of a hat that you sent has a couple of extra rectangles stuck beyond the left hand side of the view-box which may be confusing it, but that seems to be a mistake in the image, not the parser (?)

Thanks so much for your involvement… Even I believed that the image is faulty and hence I’ll probably not use it… The problem is that there are a bunch of such images… Anyways I’m not giving up on it yet and will keep you updated if I find something worth sharing… Take care then…

As it was anticipated JUCE is having no errors regarding the .svg file that I was talking about… They were some corrupted files which can be corrected by external softwares like Inkscape…

sorry wrong post

2 Likes