Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for loading a file as a base64 encoded string. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidbruce
Copy link

I needed this functionality for loading some .png files at compile time.

Helper Macro I'm using that relies on compiletime:

class ImageHelper {
    #if java
    public static function imageFromBase64(base64: String) {
        var decoder = Base64.getDecoder();
        return new ByteArrayInputStream(decoder.decode(base64)); 
    }
    #end
 
    macro public static function load(path: String): ExprOf<String> {
        return  macro {
              ImageHelper.imageFromBase64(CompileTime.readFileAsBase64($v{path}));
        };
    }
}

Actual usage:

public function loadAll(display: Display) {
        Bold =          new Image(display, ImageHelper.load("images/format-bold.png"));
        Italic =        new Image(display, ImageHelper.load("images/format-italic.png"));
        Underline =     new Image(display, ImageHelper.load("images/format-underline.png"));
        Strikeout =     new Image(display, ImageHelper.load("images/format-strikethrough-variant.png"));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant