2017-07-11 265 views
0

我需要檢查圖像是否有像25px25p這樣的特殊信息,因此我不保存來自我們郵件(Xing,LinkedIn,Twitter等)的所有圖像。從郵件中檢索圖像的工作方式應該如何。EWS - 圖像大小/尺寸

我有一個小程序從服務器檢索電子郵件並將它們保存到數據庫。它還保存所有附件。必要的部分代碼如下:

else if (attachment is FileAttachment || attachment.IsInline) 
{ 
    FileAttachment fileAttachment = attachment as FileAttachment; 
    fileAttachment.Load(); 

    string sfilename = fileAttachment.Name; 
    string sContentType = fileAttachment.ContentType; 

    using (var fs = new MemoryStream(fileAttachment.Content)) 
    { 
     using (BinaryReader br = new BinaryReader(fs)) 
     { 
       byte[] bytes = br.ReadBytes((int)fs.Length); 

       var oSQLConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["..."].ConnectionString); 
       var cmd = new SqlCommand(); 
       cmd.Connection = oSQLConnection; 
       cmd.CommandType = CommandType.Text; 
       string sTicketID = gTicketID.ToString() ?? string.Empty; 
       cmd.CommandText = "INSERT INTO TBL_Attachment (fkTicketID, fkMailID, FileName, ContentType, Data)VALUES('"+sTicketID+"', '"+snFile+"', '"+sfilename+"', '"+sContentType+"', @Data)"; 

       var DataParameter = new SqlParameter("@Data", SqlDbType.Binary); 
       cmd.Parameters.Add(DataParameter); 
       DataParameter.Value = bytes; 

. 
. 
. 

我將文件轉換爲字節,並將其保存到數據庫中。

是否有可能獲得if語句的文件/圖像messurements?

回答

0

我發現了一個明顯的解決方案。我只是不得不將我的MemoryStream轉換爲圖像並檢查和高。

using (var fs = new MemoryStream(fileAttachment.Content)) 
{ 
    Image image = System.Drawing.Image.FromStream(fs); 
    if (!(image.Width == 190 && image.Height == 45)) 
    { 
     using (BinaryReader br = new BinaryReader(fs)) 
     { 
     ... 
相關問題