Converting 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'


I have an image stored on disk, that I am manipulating using the Drawing classes, and creating a 300x400 thumbnail from. Then, I want to display this image in an Image control on my webpage. How do I do that?


                    //Create the delegate
                    System.Drawing.Image.GetThumbnailImageAbort dummyCallBack;
                    dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

                    //Get the image
                    System.Drawing.Image fullSizeImg;
                    fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl));

                    //Create Thumbnail
                    System.Drawing.Image thumbNailImg;
                    thumbNailImg = fullSizeImg.GetThumbnailImage(300, 400, dummyCallBack, IntPtr.Zero);
                    imgHeadshot = (Image)thumbNailImg;    //error here: Cannot convert 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'

    bool ThumbnailCallback()
        return false;


and learning..
1/17/2008 5:39:32 PM 1803 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 25
Get it on Google Play
Get it on Apple App Store

You are going to have to set the imageurl of imgHeadshot to the actual saved path of the thumbnail on the server. 

If my reply helps answer your question then please mark as answer.
1/17/2008 6:05:21 PM

 ok then how would I save the Drawing.Image to disk?
I tried:                    thumbNailImg.Save(imageUrl);

but it gave me error:         ex.Message    "A generic error occurred in GDI+."    string

and learning..
1/17/2008 6:13:07 PM

I ended up implementing this issue in another way since I didnt get any responses. Thanks. 

and learning..
1/22/2008 10:26:15 PM

Similar Artilces:

'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
In my aspx page, I have the following snippet: <%@ Page Language="C#" %><%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Drawing" %>     public System.Drawing.Image Test()    {      ...    }  I keep getting the 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image' error in my Test function (which returns an Image). How do I fix this? Right which is possible; use the full...

CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
 CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'   <%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing" %> <%@Import Namespace="System.Drawing.Imaging" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><script type="text/C#" runat="server"> void Page_Load() {//The @ means "Ignore escape characters!" in the following string. It is a verbatim //literal string - any backslashes (and newlines) in...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

'Click' is not an event of 'System.Web.UI.WebControls.Image'
Hi, I have an imagebutton named pbx in asp page. My Codes: AddHandler pbx.Click, AddressOf Me.pbx_onClick Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs)         a few code line......... End Sub when i try to publish to site ,i get an error : 'Click' is not an event of 'System.Web.UI.WebControls.Image' How can I solve this problem? I'm not a VB guy, but try adding "Handles pbx.Click" to the end of your second line Public Sub pbx_onClick(ByVal sender As Object, ByV...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Error Serializing Value 'System.Web.UI.WebCOntrols.TreeNode' of type 'System.Web.UI.WebCOntrols.TreeNode'
Hi, I am  getting the error stated in the subject when i am storing a TreeNode in a ViewState and then using it as follows if (ViewState["ProductCounty"]!=null) { TreeNode _productCountyNode = DataTree.FindNode(((TreeNode)ViewState["ProductCounty"]).ValuePath); _productCountyNode.Expand(); } what could be causing this error? Hi, I believe TreeNode isn't serializable in a way its required for objects which can be put to ViewState - as reference - (TreeNode implements IStateManager and is meant to work together with TreeView itself saving it...

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid"...

Error 17 Argument '2': cannot convert from 'System.Web.UI.WebControls.FontSize' to 'float'
Error 17 Argument '2': cannot convert from 'System.Web.UI.WebControls.FontSize' to 'float' Error 16 The best overloaded method match for 'System.Drawing.Font.Font(string, float, System.Drawing.FontStyle)' has some invalid arguments Code:chart.DrawString(Convert.ToString(barValue[i]), new Font("arial", FontSize.Small, FontStyle.Regular), TEXT_COLOR, (columnSpacing + CHART_LEFT_MARGIN), (BMP_HEIGHT - (CHART_BOTTOM_MARGIN - (currentBarHeight - BAR_LABEL_SPACE)))); Any solution? I would be grateful for any help. new Font("...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

'Out of memory' / 'Parameter is not valid' at 'System.Drawing.Image' load
 Hi,   i have a problem with loading images. what is interesting the same type of images, the same directories some of them are loading some - not. The image size doesn't matter. It happens on a big sized and on a small sized image. So..   int id = Int32.Parse(Request.Params["id"].ToString());string sImage = "";Response.Clear();Response.ContentType = "image/JPEG";Response.Expires = 0;Response.Buffer = true;Response.Clear();sImage = GetMarkImagePath(id);FileStream fs = new FileStream(sImage, FileMode.Open, FileAccess.Read);// the foll...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Hi, any idea why I'm getting the following error?Line 45: protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) Line 46: { Line 47: TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; Line 48: int Quantity = Convert.ToInt32(QuantityTextBox.Text); Line 49: Are you sure that the control at CartGrid.Rows[e.RowIndex].Cells[2].Controls[0] isn't a LiteralControl?  How are you creating code this in your code?Brent JenkinsASP.NET, C#, Web  ...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'
Hello, Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated.  Using the code below I receive the error message above.  Please tell me what am I doing wrong? Do I need to cast the text as a literal?  Please help? Thank you in advance, <%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR"...

'System.Web.UI.WebControls.HiddenField' cannot be converted to 'HiddenField'
Hi, I have a page called ImageUpload.aspx which is a content page.  I have a number of HiddenFields on the page and have exposed them as public properties so I can retrieve them on a Crosspage Postback.   However I keep getting the rather cryptic message below stating that I cant convert a HiddenField to a HiddenField!  Any advice appreciated.   i   Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Mes...

Web resources about - Converting 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image' -

Resources last updated: 12/4/2015 9:02:28 AM