2016-08-10 8 views
0

私のサーバのpublic/imagesフォルダには、jpg imageに2048x1536ピクセルと290kbをアップロードしました。データベースからiTextSharpとasp画像を使って画像をリサイズするC#

私は、フィールドPicにMySQLテーブルデータベースにこのリンクを覚えている:私はiTextSharp libraryを使用してPDFファイルにこのイメージを印刷する必要があるhttp://mywebserver.xxx/aspx/public/images/IMG0006A.jpg

と、元のファイルサイズがページPDFオフになっているので、この画像をリサイズ。

私はこの類似点を見つけました。questionと私はpdfファイルに出力されたjpg画像が出力ページに常に出力されているので、成功なしに提案を試しました。

これを解決するにはどうすればよいですか?

私を助けることができますか?

ありがとうございます、私のコードは以下のとおりです。コードビハインド

.aspxのマークアップ

<table border="1"> 
    <tr> 
     <td colspan="2"> 
      <label for="Pic"> 
       Pic<br /> 
      </label> 
      <asp:Image ID="Pic" runat="server" /></td> 
    </tr> 
</table> 

は.cs、私が使用していないとiTextSharpライブラリを知っているが、私はあなたが解決しないと思う

if (!String.IsNullOrEmpty(reader["Pic"].ToString())) 
    { 
     lbPic.ImageUrl = reader["Pic"].ToString(); 
     iTextSharp.text.pdf.PdfPCell imgCell1 = new iTextSharp.text.pdf.PdfPCell(); 
     iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance(Server.MapPath("\\public\\images\\IMG0006A.jpg")); 
     imgCell1.AddElement(new Chunk(img1, 0, 0)); 
     img1.ScaleToFit(120f, 155.25f); 
     img1.ScaleAbsolute(120f, 155.25f); 
    } 
+0

のヘルプであることを願っています。 。 – mkl

答えて

1

この問題はサイズ変更イメージメソッドアップロードファイル

private int ResizeMethod(FileUpload upload, int iFileCnt) 
{ 
    Stream strm = upload.PostedFile.InputStream; 
    using (var image = System.Drawing.Image.FromStream(strm)) 
    { 
     int newWidth = 450; 
     int newHeight = 350; 

     var thumbImg = new Bitmap(newWidth, newHeight); 
     var thumbGraph = Graphics.FromImage(thumbImg); 
     thumbGraph.CompositingQuality = CompositingQuality.HighQuality; 
     thumbGraph.SmoothingMode = SmoothingMode.HighQuality; 
     thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; 
     var imgRectangle = new Rectangle(0, 0, newWidth, newHeight); 
     thumbGraph.DrawImage(image, imgRectangle); 

     string extension = Path.GetExtension(upload.PostedFile.FileName); 
     string targetPath = Server.MapPath("\\public\\images\\" + upload.FileName.ToString()); 
     thumbImg.Save(targetPath, image.RawFormat); 
     iFileCnt += 1; 
    } 

    return iFileCnt; 
} 

これは私があなたのセルとあなたのイメージオブジェクトの両方が、そうでない場合は使用されずにそのスニペットの最後で範囲外であるとして、画像が全く表示することができますか疑問you-が

関連する問題