我需要从数据库中检索二进制映像。如何在ASP.NET中使用C#从数据库中检索二进制映像
我的查询如下。
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=MyGames;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Select blueBallImage from CorrespondingBall WHERE objective = Default Ball", con);
我不知道如何检索blueBallImage这是一个二进制图像。
成功检索后,我需要使用包含文本的下拉列表将文本添加到图像上。代码如下。
Bitmap bmp = new Bitmap(@"C:\Users\apr13mpsip\Documents\Visual Studio 2012\WebSites\CorrespondingBallWebSite\Images\blueBallDefault.png");
目前,我不知道如何检索图像。因此,我硬编码它,我不想要的。我想从数据库中检索它。
Graphics gra = Graphics.FromImage(bmp);
gra.DrawString(ddlCharacter.Text, new Font("Verdana", 18), Brushes.Black, new PointF(4, 6));
MemoryStream ms1 = new MemoryStream();
bmp.Save(ms1, ImageFormat.Png);
var base64Data = Convert.ToBase64String(ms1.ToArray());
imgImage.ImageUrl = "data:image/png;base64," + base64Data;
Thank you. However, I do not want to display the image it out yet. How can you set the image to Bitmap? –
with this -> TypeConverter和之后 - >位图MyBitmap =(位图)tc.ConvertFrom(imgBytes);我在答案中添加了一个示例。你可以看到:-)。告诉我后,如果它的工作或没有 –
是的,它的工作!非常感谢你! –