awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
385 stars 89 forks source link

Getting the Image #16

Closed Willy-Kimura closed 5 years ago

Willy-Kimura commented 5 years ago

Is there a way one can get the currently set FontAwesome Image/Icon? As of currently, there seems to be no way.

Seems the base Image doesn't return the applied FontAwesome Icon since it's serialization is hidden.

Willy-Kimura commented 5 years ago

Just found the Extension method ToBitmap(int size, Color color).

For anyone who would wish to do this - firstly, ensure you've imported the namespace FontAwesome.Sharp:

// You can define your store image.
Image image;

// Set your preferred FontAwesome Icon.
myIconPictureBox.IconChar = IconChar.Facebook;

// Set you store-image to the applied Icon.
image = myIconPictureBox.IconChar.ToBitmap(21, color);

An even easier way is using the IconChar enum. Here you can write a method that returns a FontAwesome Icon like this:

public Image GetFAIcon(IconChar icon, int size, Color color)
{
    IconChar iconChar = icon;
    return iconChar.ToBitmap(size, color);
}

And here's an example using the method:

pictureBox.Image = GetFAIcon(IconChar.Facebook, pictureBox.Height, Color.Blue)

mkoertgen commented 5 years ago

Exactly. Using IconHelper you can even create (WPF) images for custom fonts, e.g. Material Design. We could probably add another helper method to FormsIconHelper. Would you make use of it?

Willy-Kimura commented 5 years ago

Great add. I'd very much appreciate a helper class for such use-cases!

Willy-Kimura commented 5 years ago

A WinForms example using the helper class and other associated methods can likewise assist very much.

mkoertgen commented 5 years ago

Ok, we are going for it! :+1:

mkoertgen commented 5 years ago
mkoertgen commented 5 years ago

Doing some last checks before pushing the updated package. Hang tight.