简体   繁体   中英

How can I draw legible text on a bitmap (Winforms)?

I've written a photo viewer, and I want to superimpose text over the photo. I want the font or font color to make the text as legible as possible on top of the bitmap, no matter what the underlying bitmap looks like.

My current thinking is to take the region of the bitmap where the text will appear, and make some kind of "overall color" calculation for that area, and then set the font color to be something correspondingly contrasting.

However, this math is way over my head. Has anybody seen a method for making this type of "what's the average color of all of these pixels" calculation? Or is that not even the best approach?

EDIT: I'm moving the second portion of this to another question.

You can use this to calculate average color of a region of bitmap: How to calculate the average rgb color values of a bitmap Do you store your image as a Bitmap ?

You can also draw an outlined text. For example, white text with black outline. This will make text visible on most of backgrounds: How to Drawing Text with Outline onto Images?

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