就是说假如我的一个图片被分成了三次读取,第一个块很正常,很清楚,但第二个快就不清楚了,失真了,第三个快就更厉害了
代码中我使用copyto把byte[]拼装起来的
我怀疑是不是16进制前面的0x收的影响string strID = Request.QueryString["id"].ToString();
SqlConnection conn = new SqlConnection("Server=localhost;UID=sa;Password=;database=DBTEST;Connection Reset=FALSE;");
conn.Open(); SqlCommand cmd = new SqlCommand("SELECT datalength(photo) from employees where employeeID=" + strID, conn);
int intLength = (int)cmd.ExecuteScalar(); SqlDataAdapter da2 = new SqlDataAdapter("SELECT photo from employees where employeeID=" + strID,conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
byte[] b2 = (byte[])ds2.Tables[0].Rows[0][0];
byte[] b = new byte[intLength];
bool flag = true;
string strSQL = "Declare @ptrval varbinary(16);SELECT @ptrval = TEXTPTR(photo) from employees where employeeID=" + strID;
int i = 0;
int index = 0;
while(flag)
{
//count++;
//System.Threading.Thread.Sleep(0);
int l = 3200000;
int lt = l;
int j = i;
if(j+lt+1>=intLength)
{
l = intLength-j;
flag = false;
}
string strSQL2 = ";READTEXT employees.photo @ptrval " + i.ToString() + " " + l.ToString();
i=i+l+1;
SqlDataAdapter da = new SqlDataAdapter(strSQL + strSQL2,conn);
DataSet ds = new DataSet();
da.Fill(ds);
byte[] ptr = (byte[])ds.Tables[0].Rows[0]["photo"];
ptr.CopyTo(b,index);
index = index + ptr.Length;
//ptr = null;
}
Response.Clear();
Response.ContentType = "image/jpeg"; Response.BinaryWrite(b);
conn.Close();
代码中我使用copyto把byte[]拼装起来的
我怀疑是不是16进制前面的0x收的影响string strID = Request.QueryString["id"].ToString();
SqlConnection conn = new SqlConnection("Server=localhost;UID=sa;Password=;database=DBTEST;Connection Reset=FALSE;");
conn.Open(); SqlCommand cmd = new SqlCommand("SELECT datalength(photo) from employees where employeeID=" + strID, conn);
int intLength = (int)cmd.ExecuteScalar(); SqlDataAdapter da2 = new SqlDataAdapter("SELECT photo from employees where employeeID=" + strID,conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
byte[] b2 = (byte[])ds2.Tables[0].Rows[0][0];
byte[] b = new byte[intLength];
bool flag = true;
string strSQL = "Declare @ptrval varbinary(16);SELECT @ptrval = TEXTPTR(photo) from employees where employeeID=" + strID;
int i = 0;
int index = 0;
while(flag)
{
//count++;
//System.Threading.Thread.Sleep(0);
int l = 3200000;
int lt = l;
int j = i;
if(j+lt+1>=intLength)
{
l = intLength-j;
flag = false;
}
string strSQL2 = ";READTEXT employees.photo @ptrval " + i.ToString() + " " + l.ToString();
i=i+l+1;
SqlDataAdapter da = new SqlDataAdapter(strSQL + strSQL2,conn);
DataSet ds = new DataSet();
da.Fill(ds);
byte[] ptr = (byte[])ds.Tables[0].Rows[0]["photo"];
ptr.CopyTo(b,index);
index = index + ptr.Length;
//ptr = null;
}
Response.Clear();
Response.ContentType = "image/jpeg"; Response.BinaryWrite(b);
conn.Close();
解决方案 »
- Gridview 数据导出到Excel 急在线等.
- 服务器button控件的OnClientClick不执行
- 我现在在常州,北京的拥有让我去面试,我现在没有工作,大家觉得我该怎么办?
- 求助:asp中表格隐藏
- 同志们关于DataGrid问题,有个问题想跟大家交流一下???
- 请问现在研究 DotNetNuke的人多吗?这东西我觉得很好.
- 新手提问
- 为什么我的IIS连接不到本地计算机了啊 重装了也不行?
- 有公司采用SharePoint Portal Server 2003平台的吗?
- 请问如何将用DATAGRID控件绑定的数据中的一列设为超级链接
- 數據庫訪問設計(viena(维也纳N02))請進
- 如何判断文本框失去焦点,急。
FileInfo objFileInfo = new FileInfo(@"c:\1.jpg");
byte[] abContent = new byte[objFileInfo.Length];
FileStream objFileStream = objFileInfo.OpenRead();
Response.ContentType = "image/jpeg";
int iRead;
while ((iRead=objFileStream.Read(abContent, 0, (int)(objFileInfo.Length / 3))) > 0)
{
byte[] abBuffer = new byte[iRead]; for (int i = 0; i < iRead; i++)
abBuffer[i] = abContent[i];
Response.BinaryWrite(abBuffer);
}