简体   繁体   中英

How to create outline around text in bitmap Java

I load a ttf file and create a bitmap (256x256) with transparent background, I then draw the characters (font glyphs) on the bitmap.

What I would like to do is create an thin (1 or 2 pixels) white outline around all the characters, maybe using edge detection.

How would I accomplish this?

I'm sure there's a more formal/cleaner way to do this, but if you only need a 1 pixel border, why not just render the font as white 4 times, one for each diagonal 1-pixel offset, and then draw the black over it?

Ie, draw white at (x-1,y-1), (x-1,y+1), (x+1,y-1), (x+1,y+1), then draw black at (x,y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM