直接使用企业管理器好像没有办法 *** 作吧,通过软件或自己做个小软件读取。
#region //读取数据库中到内存并显示
public void LoadToMemoryAndDisable(string serverAdress, string database)
{
//读取数据库中到内存并显示
SqlConnection conn = new SqlConnection("server=" + serverAdress + ";integrated security = sspi;database = " + database);
SqlCommand cmd = new SqlCommand("select from imgtable where imgname like '%bmp%'", conn);
connOpen();
SqlDataReader dr;
try
{
dr = cmdExecuteReader();
drRead();
SystemDataSqlTypesSqlBinary sb = drGetSqlBinary(2);
//或byte[] imageData = (byte[])dr[2];
MemoryStream ms = new MemoryStream(sbValue);//在内存中 *** 作数据
Bitmap bmp = new Bitmap(BitmapFromStream(ms));
thispictureBox1Image = bmp;
drClose();
}
catch (Exception ex)
{
MessageBoxShow(exMessage);
}
finally
{
connClose();
}
}
#endregion
从数据库读取二进制文件
然后从二进制读取的信息:
byte[] picData = cursorgetBlob(cursorgetColumnIndex("pic_data"));
bitmapsetImageBitmap(BitmapFactorydecodeByteArray(picData, 0, picDatalength));
通过后台上传的时候一般先将存入服务器指定路径中而在数据库中只保存的位置也就是路径
前台通过FLASH调用并显示的过程:
通过WEB开发语言ASP/PHP/JS等读出数据中的位置,然后可以用向FLASH传递变量的方法让FLASH获取位置并显示另一种方法是通过WEB开发语言将数据内容转换为XML文档再由FLASH读取XML文档内容
也可用xml文件作为中间文件转接简单的也可直接用xml作为数据库存取
复杂的结合php或asp再链接数据库如果不懂可以把自己的机器设成服务器自己多测试几次即可
首先,在数据库中要建立相应的字段能保存Bytes,例如在SQL Server中用Image类型来定义字段。我所用到的数据库大致结构如下:
字段名
类型
备注
FileID
Int
自增字段
FileName
Varchar(256)
FullName
Varchar(1024)
FileData
Image
然后就是写入数据库,代码如下:
FileInfo fi = new FileInfo( txtFileNameText );// Replace with your file name
if ( fiExists)
{
byte[] bData = null;
int nNewFileID = 0;
// Read file data into buffer
using ( FileStream fs = fiOpenRead() )
{
bData = new byte[fiLength];
int nReadLength = fsRead( bData,0, (int)(fiLength) );
}
// Add file info into DB
string strQuery = "INSERT INTO FileInfo "
+ " ( FileName, FullName, FileData ) "
+ " VALUES "
+ " ( @FileName, @FullName, @FileData ) "
+ " SELECT @@IDENTITY AS 'Identity'";
SqlCommand sqlComm = new SqlCommand( strQuery, sqlConn );
sqlCommParametersAdd( "@FileName", fiName );
sqlCommParametersAdd( "@FullName", fiFullName );
sqlCommParametersAdd( "@FileData", bData );
// Get new file ID
SqlDataReader sqlReader = sqlCommExecuteReader();
if( sqlReaderRead() )
{
nNewFileID = intParse(sqlReaderGetValue(0)ToString());
}
sqlReaderClose();
sqlCommDispose();
if( nNewFileID > 0 )
{
// Add new item in list view
ListViewItem itmNew = lsvFileInfoItemsAdd( fiName );
itmNewTag = nNewFileID;
}
}
而读出的代码如下:
// Get new file name
string strFullName = dlgFBSaveSelectedPath;
if( strFullName[strFullNameLength - 1] != '\\' )
strFullName += @"\";
strFullName += lsvFileInfoSelectedItems[0]Text;
string strQuery = "SELECT FileData FROM FileInfo "
+ " WHERE FileID = " + lsvFileInfoSelectedItems[0]TagToString();
SqlDataAdapter sqlDAdapter = new SqlDataAdapter(strQuery,sqlConn);
DataSet sqlRecordSet = new DataSet();
byte[] bData = null;
//Get file data from DB
try
{
sqlDAdapterFill( sqlRecordSet, "FileInfo" );
foreach( DataRow dr in sqlRecordSetTables["FileInfo"]Rows)
{
if( dr["FileData"] != DBNullValue )
bData = ( byte[] )dr["FileData"];
}
}
catch(SqlException sqlErr)
{
MessageBoxShow( sqlErrMessage );
}
catch
{
MessageBoxShow( "Failed to read data from DB!" );
}
sqlRecordSetDispose();
sqlDAdapterDispose();
if( bData != null )
{
// Save file
FileInfo fi = new FileInfo( strFullName );
if( !fiExists )
{
//Create the file
using (FileStream fs = fiCreate())
{
fsWrite( bData, 0, bDataLength);
}
}
else
{
//Create the file
using (FileStream fs = fiOpenWrite())
{
fsWrite( bData, 0, bDataLength);
}
}
}
不过需要提的一点,如果把大量的文件存入数据库的话,会造成数据库的臃肿,而且访问量也会增大。所以现在比较流行的做法,是把文件上传到服务器上,而在数据库上只保存文件的相对路径即可。那么访问的时候,先通过数据库得到文件的相对路径,然后再访问服务器上的文件
以上就是关于数据库以img存储,如何读取图片全部的内容,包括:数据库以img存储,如何读取图片、android 如何读取数据库中的图片、FLASH怎么读取edb数据库中的图片等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)