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

code convert to Color add zeroes bug #1

Open
hocgin opened this issue Mar 27, 2020 · 1 comment
Open

code convert to Color add zeroes bug #1

hocgin opened this issue Mar 27, 2020 · 1 comment

Comments

@hocgin
Copy link

hocgin commented Mar 27, 2020

image

This Code

public class Avatars {
    public static final Avatar AVATAR = GitHubAvatar.newAvatarBuilder()
        .build();

    public static File getAvatarFile(long code) {
        return getFile(Avatars.AVATAR, code);
    }

    private static File getFile(Avatar avatar, long code) {
        int size = avatar.getWidth();
        BufferedImage dest = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = dest.createGraphics();
        AvatarUtils.activeAntialiasing(g2);
        g2.drawImage(avatar.create(code), 0,  0, size, size, null);
        g2.dispose();
        return toFile(dest);
    }

    private static File toFile(BufferedImage bi) {
        Path file;
        try {
            file = Files.createTempFile("img", ".png");
            ImageIO.write(bi, "png", file.toFile());
            return file.toFile();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws IOException {
        final File avatarFile = getAvatarFile(0L);
        Desktop.getDesktop().open(avatarFile);
    }
}

This Exception

Exception in thread "main" com.talanlabs.avatargenerator.AvatarException: Failed to build avatar
	at com.talanlabs.avatargenerator.Avatar.buildAll(Avatar.java:128)
	at com.talanlabs.avatargenerator.Avatar.create(Avatar.java:71)
	at in.hocg.eagle.basic.lang.Avatars.getFile(Avatars.java:34)
	at in.hocg.eagle.basic.lang.Avatars.getAvatarFile(Avatars.java:26)
	at in.hocg.eagle.basic.lang.Avatars.main(Avatars.java:51)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 6
	at java.lang.String.substring(String.java:1963)
	at com.talanlabs.avatargenerator.utils.AvatarUtils.extractColor(AvatarUtils.java:196)
	at com.talanlabs.avatargenerator.element.GitHubElementRegistry.buildImage(GitHubElementRegistry.java:32)
	at com.talanlabs.avatargenerator.element.AbstractImageElementRegistry.getElement(AbstractImageElementRegistry.java:21)
	at com.talanlabs.avatargenerator.Avatar.buildAvatarImage(Avatar.java:150)
	at com.talanlabs.avatargenerator.Avatar.buildAll(Avatar.java:108)
	... 4 more
@gabrie-allaigre
Copy link
Owner

Hi,
addZeroes must be corrected

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

No branches or pull requests

2 participants