I have a PictureBox that its size is fixed to 480×360 pixels. I write some text using DrawString on the image in the picturebox. If size of the image that user is selecting for the picturebox is already 480×360, it is no problem!
Problems starts when user is adding an image with smaller or greated size of default 480×360 pixels. In this case the default fonr size that I am writing strings on the images will be either too big or too small.
Is there a way to select font size depending on the images width and height? The pictures I am using in the program mostly are 4:3 ratio.
At the moment I am using the code below…it is somehow working but it is not a good way for doing so. What can be a smarter way?!
private int GetProperFontSize()
{
var width = _bitmap.Width;
if(width > 480 && width <= 680)
{
return 20;
}
if (width > 680 && width <= 800)
{
return 24;
}
if (width > 800 && width <= 1024)
{
return 32;
}
if (width > 1024 && width <= 1600)
{
return 44;
}
if (width > 1600 && width <= 2048)
{
return 50;
}
if (width > 2048 && width <= 2560)
{
return 66;
}
if (width > 2560 && width <= 6000)
{
return 80;
}
return 16;
}
you can prohibit the user from using images of a smaller size…with the larger size simply scale it to the constrained width. you can also try things like setting a background color of black, centering the image, and then placing a white band at the bottom for the text like a polaroid…