DotImage使用教程:从数据库中读写图像
来源:互联网 发布:龙记模架报价软件下载 编辑:程序博客网 时间:2024/06/04 19:40
.Net图像处理控件AtalasoftDotImage具有流媒体功能,可与ADO.NET共同使用以直接读取数据库中的图像,无需保存至临时文件。下面代码片段演示了如何利用C#和VB.NET从数据库中读写图像。
写入数据库:
C#
private void SaveToSqlDatabase(AtalaImage image){SqlConnection myConnection = null;try{// Save image to byte array.byte[] imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75));// Create the SQL statement to add the image data.myConnection = new SqlConnection(CONNECTION_STRING);SqlCommand myCommand = new SqlCommand("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection);SqlParameter myParameter = new SqlParameter("@Image", SqlDbType.Image, imagedata.Length);myParameter.Value = imagedata;myCommand.Parameters.Add(myParameter);// Open the connection and execture the statement.myConnection.Open();myCommand.ExecuteNonQuery();}finally{myConnection.Close();}}
Visual Basic.NET
Private Sub SaveToSqlDatabase(ByVal image As AtalaImage)Dim myConnection As SqlConnection = NothingTry' Save image to byte array.Dim imagedata() As Byte = image.ToByteArray(New Atalasoft.Imaging.Codec.JpegEncoder(75))' Create the SQL statement to add the image data.myConnection = New SqlConnection(CONNECTION_STRING)Dim myCommand As SqlCommand = New SqlCommand("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', @Image)", myConnection)Dim myParameter As SqlParameter = New SqlParameter("@Image", SqlDbType.Image, imagedata.Length)myParameter.Value = imagedatamyCommand.Parameters.Add(myParameter)' Open the connection and execture the statement.myConnection.Open()myCommand.ExecuteNonQuery()FinallymyConnection.Close()End TryEnd Sub
从数据库中读取:
C#
private AtalaImage OpenFromSqlDatabase(){SqlConnection myConnection = null;try{// Establish connection and SELECT statement.myConnection = new SqlConnection(CONNECTION_STRING);SqlCommand myCommand = new SqlCommand("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection);myConnection.Open();// Get the image from the database.byte[] imagedata = (byte[])myCommand.ExecuteScalar();if (imagedata != null){AtalaImage image = AtalaImage.FromByteArray(imagedata);return image;}else{MessageBox.Show("Image does not exist in database.");return null;}}finally{myConnection.Close();}}
Visual Basic .NET
Private Function OpenFromSqlDatabase() As AtalaImageDim myConnection As SqlConnection = NothingTry' Establish connection and SELECT statement.myConnection = New SqlConnection(CONNECTION_STRING)Dim myCommand As SqlCommand = New SqlCommand("SELECT ImageData FROM Atalasoft_Image_Database WHERE Caption = '" + txtCaption.Text + "'", myConnection)myConnection.Open()' Get the image from the database.Dim imagedata() As Byte = CType(myCommand.ExecuteScalar(), Byte())If (Not imagedata Is Nothing) ThenDim image As AtalaImage = AtalaImage.FromByteArray(imagedata)Return imageElseMessageBox.Show("Image does not exist in database.")Return NothingEnd IfFinallymyConnection.Close()End TryEnd Function
- DotImage使用教程:构建PDF文档
- DotImage使用教程:转换PDF和TIFF
- DotImage使用教程: 动态调整Text Annotation的字体大小
0 0
- DotImage使用教程:从数据库中读写图像
- DotImage使用教程:构建PDF文档
- DotImage使用教程: 动态调整Text Annotation的字体大小
- 从数据库中读写图片
- 从数据库中读取图像
- BarCode Reader SDK使用教程:如何从图像中读取条码
- ImageKit使用教程:数据库中图像数据的显示和检索
- matlab中图像读写
- 使用OpenCV从视频中捕获图像
- 使用BCB在数据库中插入图像及读出图像
- 使用BCB在数据库中插入图像及读出图像
- Java使用imageio 读写图像
- Java使用imageio 读写图像
- 使用wxWidgets从资源文件中静态装载图像
- GDI+中使用Image从IStream创建图像
- 使用ffmpeg从视频中截取图像帧
- 如何使用matlab从视频中提取出一帧帧图像
- 使用ffmpeg从视频中截取图像帧
- C++ primer plus 第二章
- URI是什么,在Android中有什么作用?
- test
- iframe调用别的网站的iframe并且更改其显示样式
- 关于静态映射报错!!!
- DotImage使用教程:从数据库中读写图像
- IOS录音发送
- 南阳nyoj586疯牛 和nyoj619详解总结
- android手机 wifi adb
- 排序算法
- eclipse/myeclipse中重要的快捷键
- eclipe启动报错Multiple Contexts have a path of
- redhat下查看进程占用端口和端口占用进程命令
- RTP封装h264