Wednesday, 15 April 2015

assign bitmap to an asp:image control within gridview -


I think there is something wrong here.

What I want to do is show thumbnail image inside Gridview.

ASPX page has a gridview and ASP: image control for asp image: image control comes from a website.

Once I get the image URL, I want to present the image as thumbnail as the resizeImage function is under. Lastly, I want to provide thumbnails in the Gridview column, which shows the thumbnail image as the code given below.

  Protected Zero SearchResults_RowDataBound (Object Sender, GridViewRowEventArgs e) {if (e. Row.RowType.Equals (DataControlRowType.DataRow)) {System.Web.UI.WebControls.Image imgNew = (System.Web.UI.WebControls.Image) e.Row.FindControl ("ProductThumbField"); ImgNew.Source = Utils.ResizeImage (imgNew.ImageUrl.ToString (), 6060); }}   

Here is the code that resizes the image. (taken from an example by the stack overflow question and answer).

  Private static bitmap ResizeImage (string file name, int maxWidth, int maxHyight) {using (System.Drawing.Image originalImage = System.Drawing.Image.FromFile (filename)) {/ / Caluate new size int newWidth = originalImage.Width; Int NewHight = Original Image height; Double aspect aarti = (double) original image. With / (double) original image. height; If (aspect artio & lt; = 1 & original image.Wide> MaxWide) {newWidth = maxWidth; NewHeight = (int) math.Round (Nudity / Episiertrio); } And if (aspect arteo & gt; 1 & original image.height> gt; maxhight) {newHeight = maxHeight; NewWind = (Int) Math. Round (newheit * apertio); } Bitmap newImage = new bitmap (Nudity, NewHead); (Graphics G = Graphics. Frame image (new image)) {// - Adjust quality settings to fit your application g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; G.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; G.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; G.DrawImage (original image, 0, 0, new image with, new image. High); New image refund; }}   

ASPX is the code snippet of the page.

  & lt; ASP: Gridview id = "Search Result" Runat = "Server" AutoGenerateColumns = "false" EnableViewState = "false" Allow = "true" PageSize = "10" ondatabound = "SearchResults_DataBound" & gt; & Lt; RowStyle CssClass = "EvenRow" /> & Lt; AlternatingRowStyle CssClass = "OddRow" /> & Lt; Columns & gt; & Lt; Asp: TemplateField Meta: resourceKey = "ProductThumbField" & gt; & Lt; Item Style CssClass = "Product Name Column" /> & Lt; Header style CssClass = "product name column" /> & Lt; ItemTemplate & gt; & Lt; Asp: image id = "ProductThumbImg" runat = "server" imageurl = '& lt;% # GetProductThumb (container.datetime)% & gt; Width = "60px" height = "60px" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt;  

I found that bitmap can not be assigned because bitmap is created. Drawing from asp: image is from system.web ...

No comments:

Post a Comment