As I mentioned in my A New Year’s (Image) Resolution post, I’ve had a side project that requires dealing with images that come in at varying resolutions. Regardless of resolution, though, they all have the same basic requirements. I need to be able to “stamp” the pages with a dynamic header text, the quality needs to remain high enough that they can be viewed/printed, and — ideally — I need to have the header text be relatively the same size once it’s scaled on the screen or printed.
I think I’m a little closer to where I want to be, but it’s still not quite ideal.
I have a font object that’s 10-point bold “Courier New”. I use a Generic Typographic string format with No Clip and Word Trimming. I then use the MeasureString method on my graphics object to store the string size. Once I have that, I basically just subtract the height of that object from the width and height of my target rectangle and offset my starting position of DrawImage accordingly.
What I had hoped it would do is, if writing my header required 4mm of height, I’d scale the image down enough to give me 4mm of room on both sides (to keep the same aspect ratio) and write the header text. Similarly, if the header text somehow required an inch of height, it’d scale down so there was an inch of room.
It does seem to work, but just not as good as I had hoped. On some images, the header text was very close to the original fax text (which I want). In others, though, the spacing was a bit more pronounced and I’m not quite sure why just yet.
Ideally, what I want to do next, is have a way to determine the ideal font size based on the image. If I’m dealing with a basic image at 1275×1755 (at 96dpi H-Res and 96dpi V-Res), I would need a different size font than if I was working with a 1728×1052 image (at 203dpi H-Res and 98dpi V-Res).
I just haven’t quite figured out how I’ll actually DO that… yet :)
Actually, I take that back… my true ideal solution is to toss the text on the top or bottom of the page in a spot that isn’t being used a not have to mess with the scaling at all. But that’s more of a Phase-II plan…