java oracle blob image,如何将存储为Oracle blob的图像存入Image对象

我知道这使用SQL,但它应该类似于您的需求

Dim cn As SqlConnection = Nothing

Dim cmd As SqlCommand = Nothing

Dim da As SqlDataAdapter = Nothing

Dim ms As MemoryStream = Nothing

Dim dsImage As Data.DataSet = Nothing

Dim myBytes() As Byte = Nothing

Dim imgJPG As System.Drawing.Image = Nothing

Dim msOut As MemoryStream = Nothing

Try

cn = New SqlConnection(ConnectionStrings("conImageDB").ToString)

cmd = New SqlCommand(AppSettings("sprocGetImage").ToString, cn)

cmd.CommandType = Data.CommandType.StoredProcedure

cmd.Parameters.AddWithValue("@dmhiRowno", irowno)

da = New SqlDataAdapter(cmd)

dsImage = New Data.DataSet

da.Fill(dsImage, "image")

If dsImage.Tables(0).Rows.Count = 0 Then

Throw New Exception("No results returned for rowno")

End If

myBytes = dsImage.Tables(0).Rows(0)("Frontimage")

ms = New MemoryStream

ms.Write(myBytes, 0, myBytes.Length)

imgJPG = System.Drawing.Image.FromStream(ms)

'Export to JPG Stream

msOut = New MemoryStream

imgJPG.Save(msOut, System.Drawing.Imaging.ImageFormat.Jpeg)

imgJPG.Dispose()

imgJPG = Nothing

ms.Close()

sFrontImage = Convert.ToBase64String(msOut.ToArray())

dsImage = New Data.DataSet

da.Fill(dsImage, "image")

myBytes = dsImage.Tables(0).Rows(0)("Backimage")

ms = New MemoryStream

ms.Write(myBytes, 0, myBytes.Length)

imgJPG = System.Drawing.Image.FromStream(ms)

sBackImage = Convert.ToBase64String(ms.ToArray)

Catch ex As System.IO.IOException ' : An I/O error occurs.

Throw ex

Catch ex As System.ArgumentNullException ': buffer is null.

Throw ex

Catch ex As System.NotSupportedException ': The stream does not support writing. For additional information see System.IO.Stream.CanWrite.-or- The current position is closer than count bytes to the end of the stream, and the capacity cannot be modified.

Throw ex

Catch ex As System.ArgumentOutOfRangeException ': offset or count are negative.

Throw ex

Catch ex As System.ObjectDisposedException ' : The current stream instance is closed.

Throw ex

Catch ex As System.ArgumentException

Throw ex

Catch ex As System.Runtime.InteropServices.ExternalException ': The image was saved with the wrong image format

Throw ex

Catch ex As Exception

Throw ex

Finally

If cn IsNot Nothing Then

cn.Close()

cn.Dispose()

cn = Nothing

End If

If cmd IsNot Nothing Then

cmd.Dispose()

cmd = Nothing

End If

If da IsNot Nothing Then

da.Dispose()

da = Nothing

End If

If ms IsNot Nothing Then

ms.Dispose()

ms = Nothing

End If

If msOut IsNot Nothing Then

msOut.Close()

msOut.Dispose()

msOut = Nothing

End If

If dsImage IsNot Nothing Then

dsImage.Dispose()

dsImage = Nothing

End If

If myBytes IsNot Nothing Then

myBytes = Nothing

End If

If imgJPG IsNot Nothing Then

imgJPG.Dispose()

imgJPG = Nothing

End If

End Try这段代码为前面的图像拉回了一个tiff包裹的jpeg,所以代码与后面的图像有些不同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值