# Best way to draw small images

**URL:** <https://forum.juce.com/t/best-way-to-draw-small-images/65013>\
**Category:** General JUCE discussion\
**Created:** [January 26, 2025, 8:32am UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013 "2025-01-26T08:32:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoppiMadeIt](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@JoppiMadeIt](https://forum.juce.com/u/JoppiMadeIt)\
**Post date:** [January 26, 2025, 8:32am UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013/1 "2025-01-26T08:32:40Z")

</div>

I want to draw a bypass button with a PNG/SVG image in a `juce::ImageButton` with a size of about 24px (width and height). Unfortunately, it currently looks very **pixelated** :

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/9/b/9b831401b0805998cdd4588d104bfd513f6e5a2e.png)

Since I created the texture myself in an SVG image editor, I can easily change the texture size and export it to any format.

What are the best settings to display such an image without it looking pixelated? Should I export the texture at the same size I want in the plugin (24px) or at a larger size (e.g., 4x as large)? What format should I use? Are there any filters I can apply to make it more detailed?

Here is the current code I’m using:

```auto
addAndMakeVisible(bypassButton);
juce::Image bypassIcon = juce::ImageCache::getFromMemory(BinaryData::bypass_image_png, BinaryData::bypass_image_pngSize);
bypassButton.setBounds(0, 0, 24, 24);
bypassButton.setImages(
    false, true, true,
    bypassIcon, 1.0f, juce::Colours::white,
    bypassIcon, 1.0f, juce::Colours::white,
    bypassIcon, 1.0f, juce::Colours::black.brighter(0.34f),
    0.0f);

```

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)\
**Post date:** [January 26, 2025, 11:19am UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013/2 "2025-01-26T11:19:25Z")

</div>

Hi there. Instead of exporting as PNG you could export as SVG. Then either:

- Drag-and-drop the SVG file into the Projucer’s SVG Path Conveter tool. It will create code with which you can create a juce::Path.

- Or open the SVG file with a text editor, copy the svg path string and use `Drawable::parseSVGPath` in your code to turn it into a juce::Path.

The juce::Path you can then draw at any size and it will always look good.

---

<div class="post-metadata">

**Author:** ![zsliu98](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zsliu98/32/22502_2.png) [@zsliu98](https://forum.juce.com/u/zsliu98)\
**Post date:** [January 26, 2025, 1:46pm UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013/3 "2025-01-26T13:46:52Z")

</div>

Use `DrawableButton` instead of `ImageButton`.

Then load the SVG as a `juce::Drawable`:

```auto
juce::Drawable::createFromImageData

```

And set the drawable to the button:

```cpp
drawableButton.setImages()

```

---

<div class="post-metadata">

**Author:** ![Nitsuj70](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nitsuj70/32/12754_2.png) [@Nitsuj70](https://forum.juce.com/u/Nitsuj70)\
**Post date:** [January 26, 2025, 3:47pm UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013/4 "2025-01-26T15:47:09Z")

</div>

Just in case you’re not aware of them…

There’s fontaudio: [GitHub - fefanto/fontaudio: icon toolkit for audio developers](https://github.com/fefanto/fontaudio?tab=readme-ov-file)

And from that link a link to fontawesome and a JUCE wrapper for it.

Easy to get them working as/with buttons etc.

Covers a lot of basic essentials.

---

<div class="post-metadata">

**Author:** ![ZioGuido](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zioguido/32/6975_2.png) [@ZioGuido](https://forum.juce.com/u/ZioGuido)\
**Post date:** [January 26, 2025, 4:17pm UTC](https://forum.juce.com/t/best-way-to-draw-small-images/65013/5 "2025-01-26T16:17:07Z")

</div>

Since a SVG file is basically a XML file, you can read the XML file as a string and pass it to a function that would extract and resize the path contained into it, something like this:

```
void setSVG(const String& xmlString)
{
    std::unique_ptr<XmlDocument> xml;
    xml.reset(new XmlDocument(xmlString));
    if (xml)
    {
        if (auto* drb = Drawable::createFromSVG(*xml->getDocumentElement().get()))
        {
            path = drb->getOutlineAsPath();
            path.scaleToFit(0, 0, getWidth(), getHeight(), true);
            repaint();
        }
    }
}

```

You could write your own class that inherits from ToggleButton and override the paint() function where you paint your path, maybe change its color according to toggleState, etc.
