2009-10-06 5 views
0

는 내가 SqlDataReader 개체를 사용하고 그리고 내가 액세스 파일 변환 테이블에서 읽으려고하고, 그리고 SQL 서버 2008읽기 WMF 이미지

을에 .

어떻게 변환합니까? System.Drawing.Image로 사용할 수 있습니까?

Windows MetaFile이므로 PNG 또는 GIF로 변환하여 파일 시스템에 저장하고 싶습니다.

이미지로 변환 할 수 없다는 오류가 발생하는 경우 올바르지 않습니다.

System.Drawing.Image LocationImage = sdr.GetSqlBinary(2) 

고맙습니다.

답변

1

SqlBytes을 사용하십시오. Image.FromStream을 사용하여 SqlBytes.Stream에서 이미지를로드하십시오. 큰 사이즈의 이미지를로드하는 독자에 CommandBehavior.SequentialAccess을 사용

using (SqlDataReader sdr=cmd.ExecuteReader(CommandBehavior.SequentialAccess)) 
{ 
... 
System.Data.SqlTypes.SqlBytes imageBytes = srd.GetSqBytes(2); 
System.Drawing.Image locationImage = Image.FromStream(imageBytes.Stream); 
} 

을 PNG/GIF로 저장하려면

SqlCommand cmd = new SqlCommand("update table set [email protected] where ...") 

MemoryStream streamOutput = new MemoryStream(); 
image.Save(streamOutput, ImageFormat.Png); 
SqlBytes imageBytes = new SqlBytes(streamOutput); 
cmd.Parameters.AddWithValue("@image", imageBytes); 
cmd.ExecuteNonQuery() 

업데이트

확실 Image.FromStream로드 할 수 아니에요 WMF 형식. EMF afaik를로드 할 수는 있지만 WMF에 대해서는 확실하지 않습니다. 아마도 Metafile(Stream) 생성자를 통해 호출을 라우팅 할 수 있습니다. 나는 그래픽 전문가가 아닙니다.

+0

감사합니다. Image.FromStream, 그리고 그 올바른 작동하지 않았다,하지만 메타 파일 (스트림) 사용하여이 생성자가 바이트 배열을 원하는 지 않습니다. 그래서 저는 그것에 대해 연구하고 있습니다. –