我需要从数据库中检索二进制图像.
我的疑问如下.
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);
Run Code Online (Sandbox Code Playgroud)
我不知道如何检索作为二进制图像的blueBallImage.
成功检索后,我需要使用包含文本的下拉列表在图像上添加文本.代码如下.
Bitmap bmp = new Bitmap(@"C:\Users\apr13mpsip\Documents\Visual Studio 2012\WebSites\CorrespondingBallWebSite\Images\blueBallDefault.png");
Run Code Online (Sandbox Code Playgroud)
目前,我不知道如何检索图像.因此,我硬编码了我不想要的东西.我想从数据库中检索它.
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;
Run Code Online (Sandbox Code Playgroud) 我想将二进制图像显示到名为'gvExistedCharacter'的网格视图中.我做过关于它的研究,其中许多建议使用处理程序.但是,我不知道我该怎么做.
仅供参考:数据库中图像的数据类型为image,名为"blueBallImage".我还想在同一个gridview中显示它的int级别.
我试过了
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=MyCloudGames;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Select blueBallImage FROM CorrespondingBall", con);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
SqlParameter ImageID = new SqlParameter("@characterID", System.Data.SqlDbType.Int);
ImageID.Value = context.Request.QueryString["characterID"];
cmd.Parameters.Add(ImageID);
con.Open();
SqlDataReader dReader = cmd.ExecuteReader();
dReader.Read();
context.Response.BinaryWrite((byte[])dReader["Image"]);
dReader.Close();
con.Close();
Run Code Online (Sandbox Code Playgroud)
我收到错误"参数化查询"(@characterID int)选择blueBallImage FROM CorrespondingBall'需要参数'@characterID',这是未提供的."
我想有很多方法.但是,我不想一遍又一遍地写它.我想要方法bBIntersectsB1,bBIntersectsB2,...,bBIntersectsB9,bBIntersectsB10.在每种方法中,唯一的变化是blueBallRect1,我想要blueBallRect2,...,blueBallRect9,blueBallRect10.
public bool bBIntersectsB1(Rect barTopRect, Rect barBottomRect, Rect blueBallRect1)
{
barTopRect.Intersect(blueBallRect1);
barBottomRect.Intersect(blueBallRect1);
if (barTopRect.IsEmpty && barBottomRect.IsEmpty)
{
return false;
}
else
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)