# SVG file as Image in drawImage of graphics

**URL:** <https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657>\
**Category:** General JUCE discussion\
**Created:** [November 4, 2011, 10:24am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657 "2011-11-04T10:24:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [November 4, 2011, 10:24am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/1 "2011-11-04T10:24:38Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 4, 2011, 10:46am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/2 "2011-11-04T10:46:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 4, 2011, 10:47am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/3 "2011-11-04T10:47:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [November 4, 2011, 11:06am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/4 "2011-11-04T11:06:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [January 25, 2012, 5:49am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/5 "2012-01-25T05:49:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 25, 2012, 10:20am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/6 "2012-01-25T10:20:41Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 31, 2012, 12:51pm UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/7 "2012-01-31T12:51:47Z")

</div>

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 (?)

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [February 4, 2012, 9:35am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/8 "2012-02-04T09:35:45Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [February 10, 2012, 9:41am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/9 "2012-02-10T09:41:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![shankar](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shankar](https://forum.juce.com/u/shankar)\
**Post date:** [August 26, 2014, 9:54am UTC](https://forum.juce.com/t/svg-file-as-image-in-drawimage-of-graphics/7657/10 "2014-08-26T09:54:00Z")

</div>

sorry wrong post
