1

問題は、フォントを読み込んでビットマップにレンダリングできないことです。具体的には、asp.net Web ページ コードはビットマップを作成し、テキストをビットマップに書き込もうとします。あるサーバー (Win 2003) から別のサーバー (Win 2008) にコードを移動しようとしました。Win 2003 では動作しますが、Win 2008 では動作しません。古いサーバーからフォント (.ttf) をコピーし、新しいサーバーにインストールしました。

コード:

Bitmap barcode = new Bitmap(1, 1);
ffamily = new FontFamily("Free 3 of 9"); //exception

Font threeOfNine = new Font(ffamily, 60, FontStyle.Regular, GraphicsUnit.Point);
Graphics graphics = Graphics.FromImage(barcode);
SizeF size = graphics.MeasureString(number, threeOfNine);
barcode = new Bitmap(barcode, size.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
graphics.DrawString(number, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();

次に、次の行でこの例外をスローしますnew FontFamily()

Exception information: 
Exception type: ArgumentException 
Exception message: Font 'Free 3 of 9' cannot be found. 

フォントは、Windows の Font フォルダーにインストールされています。私が試してみると:

Font threeOfNine = new Font("Free 3 of 9", 60, FontStyle.Regular, GraphicsUnit.Point);

次に、標準のデフォルト フォントを使用して Font が作成されます。セキュリティ上の問題はありますか? フォントが正しく読み込まれないのはなぜですか?

4

1 に答える 1

4

まあ、私は自分で答えを見つけました。

フォントをインストールし、適切な権限が .ttf にあることを確認した後。IIS を再起動する必要がありました。再起動に必要なのはアプリプールだけだったと思います。それからそれは働き始めました。

于 2012-08-11T00:44:26.600 に答える