0
我有一個PictureBox
,它的大小固定爲480x360像素。我使用DrawString
在圖片框中的圖片上書寫了一些文字。如果用戶爲picturebox選擇的圖像大小已經是480x360,那就沒有問題了!自動更改圖片箱中拉伸圖像的字體大小
當用戶使用較小或較大尺寸的默認480x360像素添加圖像時,會出現問題。在這種情況下,我在圖像上寫字符串的默認字體大小將會太大或太小。
有沒有辦法選擇字體大小取決於圖像的寬度和高度?我在程序中使用的圖片大多是4:3的比例。
目前我正在使用下面的代碼......它有點工作,但這不是一個好辦法。什麼可以是更聰明的方式?
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;
}
謝謝。
是的。簡單地做我下面說的。 – Timmerz 2012-03-27 19:23:32