我已在Visual Studio 2010中使用ASP.NET C#将文本转换为Image(.png)。但是提交后创建的图像无法在浏览器中显示并显示消息
无法显示图像“http:// localhost:49670 / WebSite1 / Default.aspx”,因为它包含错误。
在调试期间,没有错误或警告或类似的东西。我该如何解决这个问题?
答案 0 :(得分:0)
试试这个......
private Bitmap CreateBitmapImage(string sImageText)
{
Bitmap objBmpImage = new Bitmap(1, 1);
int intWidth = 0;
int intHeight = 0;
// Create the Font object for the image text drawing.
Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
// Create a graphics object to measure the text's width and height.
Graphics objGraphics = Graphics.FromImage(objBmpImage);
// This is where the bitmap size is determined.
intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width;
intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height;
// Create the bmpImage again with the correct size for the text and font.
objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
// Add the colors to the new bitmap.
objGraphics = Graphics.FromImage(objBmpImage);
// Set Background color
objGraphics.Clear(Color.White);
objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
objGraphics.DrawString(sImageText, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);
objGraphics.Flush();
return (objBmpImage);
}
答案 1 :(得分:0)
查看Url,您可能会将图像与HTML内容混合在一起... 使用ASHX是渲染图像的更好选择 - 请查看http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.all