oracle blob에 저장된 이미지를 검색하여 새로운 System.Drawing.Image 인스턴스에 저장하려고합니다. 스트림을 temp.bmp 파일에 디스크에 쓸 수 있고 거기에서 읽을 수 있지만 그게 충분히 나를 위해 l33t 아니에요. blob 객체를 이미지로 직접 변환하려면 어떻게해야합니까?이미지 객체에 oracle blob로 저장된 이미지를 얻는 방법
0
A
답변
1
가정 : 당신은 마이크로 소프트 클라이언트 (System.Data.OracleClient
)를 사용하는
- .
- 당신은 적절한
OracleConnection
인스턴스 (connection
)가 있습니다. - 귀하는
SELECT my_blob FROM my_table WHERE id=xx
을 기준으로OracleCommand
준비 됨 (command
)을 준비했습니다.
이 같이 가야한다 : 복사
public static Image Copy(Image original)
{
Image ret=new Bitmap(original.Width, original.Height);
using (Graphics g=Graphics.FromImage(ret))
{
g.DrawImageUnscaled(original, 0, 0);
g.Save();
}
return ret;
}
는 복사가 필요한 이유에 대한 my blog post 및/또는 KB 814675를 참조입니다
using (OracleDataReader odr=command.ExecuteReader())
{
reader.Read();
if (!dr.IsDBNull(0))
using (Stream s=(Stream)dr.GetOracleValue(0))
using (Image image=Image.FromStream(s))
return Copy(image);
}
.
0
나는이 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를 다시 끌어 비슷한해야합니다.
관련 문제
- 1. GWT RPC를 사용하여 blob로 저장된 이미지 표시
- 2. 안드로이드의 Listview에서 blob로 데이터베이스에 저장된 이미지를 표시하는 방법?
- 3. BLOB로 저장된 java 객체에 액세스하는 MYSQL 저장 프로 시저
- 4. blob로 SQLite에 저장된 파일 열기
- 5. jsp에서 이미지를 업로드하고 blob로 데이터베이스를 저장하는 방법
- 6. 객관적인 c를 사용하여 다른 객체에 저장된 변수를 얻는 방법
- 7. Python을 사용하여 MySQL 데이터베이스에 BLOB로 저장된 파일을 삽입/검색하는 방법
- 8. 이미지를 BLOB로 저장할 때 텍스트가있는 JSP에서 이미지를 표시하는 방법은 무엇입니까?
- 9. db에 저장된 div에 이미지를 표시하는 방법
- 10. 가로 모드에서 이미지를 얻는 방법
- 11. php : 이미지를 MySQL Blob로 저장 하시겠습니까?
- 12. 아직 웹캠 이미지를 얻는 방법
- 13. 이미지를 완벽하게 얻는 방법
- 14. 바코드 이미지를 얻는 방법?
- 15. 서버에 저장된 이미지를 업로드하지 못했습니다.
- 16. 루비에서 이미지를 읽고 이미지를 얻는 방법
- 17. java에서 File 객체에 drawble에서 이미지를 읽는 방법?
- 18. 문자열로 저장된 이미지를 인라인으로
- 19. 응용 프로그램 디렉토리에 저장된 이미지를 표시하는 방법
- 20. PHP MYSQL FPDF blob로 저장된 PDF 문자열 검색
- 21. BLOB로 온라인 백업 속도
- 22. UIImagePicker에서 이미지 복사본을 얻는 방법
- 23. 인스턴스 변수에 저장된 모델의 속성을 얻는 방법
- 24. 안드로이드에서 epub 도서의 이미지를 얻는 방법
- 25. 비디오 축소 이미지를 얻는 방법?
- 26. 비디오의 축소판 이미지를 얻는 방법?
- 27. 이미지를 겹치게 테이블을 얻는 방법?
- 28. NSData에서 이미지를 다시 얻는 방법
- 29. Retina 디스플레이의 저장된 이미지 업데이트
- 30. 저장된 이미지를 Google App Engine의 데이터 저장소에 업로드하는 방법은 무엇입니까?