因为想在工作、摆动对象(JLabel的、等)、表情文字中显示,所以为了实现这一点,使用this library和以下类,只显示Graphics2D中没有drawString颜色的字体
Jabel.seticon(newemojiicon ) ) :poop: );
除表情符号外,还有所有支持这些颜色的字体: EmojiOne和Noto Color Emoji
什么是单色的表情符号点作业?
publicclassemojiiconimplementsicon {
私密字体;
privatefinalstaticintdefault _ size=32;
私有int width=default _ size;
private int height=DEFAULT_SIZE;
私有字符串e moji;
publicemojiicon (字符串控制)。
this.e moji=emojiparser.parsetounicode (icon string );
设置字体(Emojione-Android );
recalculateiconwidth(emoji;
}
公共语音集字体(字符串字体)。
try {
font=font.create font (font.truetype _ font,newfile('fonts/'strfont'.TTF ' ) ).derive font (48f );
}catch(fontformatexceptione ) )
e .打印堆栈跟踪(;
}catch(ioexceptione ) {
e .打印堆栈跟踪(;
}
}
私有语音呼叫连接width (字符串控制) {
fontrendercontextfrc=newfontrendercontext (null,true,true );
rectangle 2d bounds=font.getstring bounds (icon string,frc );
width=(int ) bounds.getWidth );
height=(int ) bounds.getHeight );
}
@Override
publicvoidpainticon (组件c、图形g、int x、int y ) {
Graphics2dG2D=(Graphics2d ) g;
g2d.set font (字体);
g2d.setrenderinghint (rendering hints.key _ text _ antialiasing,rendering hints.value _ text _ antialias _ on );
g2d.setrenderinghint (rendering hints.key _ antialiasing,rendering hints.value _ antialias _ on );
G2D.Drawstring(Emoji,0,height );
}
}
我一直在网上找假羊。 我们发现here不会成为standarised (至少. TTF字体),因为它的合法字体也有颜色。 有解决这个问题的方法吗? 我真的很喜欢用电子字体