프로그래밍 방식으로 ASP.Net에서 지정된 글꼴로 비트 맵을 만들려고합니다. 아이디어는 텍스트, 글꼴 이름, 크기 색상 등이 변수에서 전달되고 글꼴 등을 사용하는 텍스트의 비트 맵이 반환된다는 것입니다. 그러나 특정 글꼴로 다음 코드를 사용하여 수행 할 수 있음을 발견했습니다. 나는 이미지와 표지 모두 굴림 또는 굴림에 주석으로 표시된 지역에서 글꼴 이름을 변경하는 경우ASP.Net에서 프로그래밍 방식으로 특정 글꼴을 사용할 수 없습니다.
<div>
<%
string fontName = "Segoe Script"; //Change Font here
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100);
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
System.Drawing.Font fnt = new System.Drawing.Font(fontName, 20);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
graph.DrawString("Help", fnt, brush, new System.Drawing.Point(10, 10));
bmp.Save(@"C:\Development\Path\image1.bmp");
this.Image1.ImageUrl = "http://mysite/Images/image1.bmp";
%>
<asp:Label ID="Label1" runat="server" Text="Label" Font-Names="Segoe Script"> <%Response.Write("Help"); %></asp:Label> //Change font here
<asp:Image ID="Image1" runat="server" />
</div>
올바른 글꼴로 나타납니다. 그러나 두 위치의 글꼴 이름을 "Segoe Script"로 변경하면 Segoe Script에 레이블이 표시되지만 이미지는 Arial과 비슷합니다.
업데이트 : 나는 PrivateFontCollection()를 사용하여 등과 같은 글꼴 파일을로드하여 작업 얻을 수있었습니다이 질문에 here을 바탕으로
.
<div>
<%
string TypeFaceName = "Segoe Script";
System.Drawing.Text.PrivateFontCollection fnts = new System.Drawing.Text.PrivateFontCollection();
fnts.AddFontFile(@"C:\Development\Fonts\segoesc.ttf");
System.Drawing.FontFamily fntfam = new System.Drawing.FontFamily(TypeFaceName);
System.Drawing.Font fnt = new System.Drawing.Font(fntfam, 13);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100);
System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
graph.DrawString("Help", fnt, brush, new System.Drawing.Point(10, 10));
bmp.Save(@"C:\Development\Path\Images\image1.bmp");
this.Image1.ImageUrl = "http://MySite/Images/image1.bmp";
%>
<asp:Label ID="Label1" runat="server" Text="Label" Font-Names="Segoe Script"> <%Response.Write("Help"); %></asp:Label>
<asp:Image ID="Image1" runat="server" />
</div>
글꼴이 웹 서버에 설치되어 있으며 paint.net을 사용하여 글꼴로 이미지를 수동으로 만들 수 있습니다. 내가 게시 한 코드는 그것이 수행 될 수 있는지를 확인하는 것입니다. 감사. – etoisarobot