问题描述
winform项目怎么样把从数据库里读出来的图片二进制流,放到image里显示?
解决方案
解决方案二:
各位大虾救命啊
解决方案三:
System.Drawing.Imageimage=newSystem.Drawing.Bitmap(流,true);就可以阿.
解决方案四:
byte[]bts=this.getdbBytes();MemoryStreamms=newMemoryStream(bts);Imageimg=Image.FromStream(ms);
解决方案五:
那怎么从数据库里读二进制数据呢?
解决方案六:
Look
解决方案七:
以下示例从MicrosoftSQLServer中的pubs示例数据库中返回发行者ID和徽标。发行者ID(pub_id)是字符字段,而徽标则是图像,属于BLOB。由于logo字段是位图,因此该示例使用GetBytes返回二进制数据。请注意,由于必须按顺序访问字段,所以将在访问徽标之前访问当前数据行的发行者ID。//AssumesthatconnectionisavalidSqlConnectionobject.SqlCommandcommand=newSqlCommand("SELECTpub_id,logoFROMpub_info",connection);//WritestheBLOBtoafile(*.bmp).FileStreamstream;//StreamstheBLOBtotheFileStreamobject.BinaryWriterwriter;//SizeoftheBLOBbuffer.intbufferSize=100;//TheBLOBbyte[]buffertobefilledbyGetBytes.byte[]outByte=newbyte[bufferSize];//ThebytesreturnedfromGetBytes.longretval;//ThestartingpositionintheBLOBoutput.longstartIndex=0;//Thepublisheridtouseinthefilename.stringpubID="";//OpentheconnectionandreaddataintotheDataReader.connection.Open();SqlDataReaderreader=command.ExecuteReader(CommandBehavior.SequentialAccess);while(reader.Read()){//Getthepublisherid,whichmustoccurbeforegettingthelogo.pubID=reader.GetString(0);//Createafiletoholdtheoutput.stream=newFileStream("logo"+pubID+".bmp",FileMode.OpenOrCreate,FileAccess.Write);writer=newBinaryWriter(stream);//ResetthestartingbyteforthenewBLOB.startIndex=0;//ReadbytesintooutByte[]andretainthenumberofbytesreturned.retval=reader.GetBytes(1,startIndex,outByte,0,bufferSize);//Continuewhiletherearebytesbeyondthesizeofthebuffer.while(retval==bufferSize){writer.Write(outByte);writer.Flush();//Repositionstartindextoendoflastbufferandfillbuffer.startIndex+=bufferSize;retval=reader.GetBytes(1,startIndex,outByte,0,bufferSize);}//Writetheremainingbuffer.writer.Write(outByte,0,(int)retval-1);writer.Flush();//Closetheoutputfile.writer.Close();stream.Close();}//Closethereaderandtheconnection.reader.Close();connection.Close();