Puxando em uma imagem dinâmica em um controle baseado em uma URL usando C # e ASP.net

StackOverflow https://stackoverflow.com/questions/116869

  •  02-07-2019
  •  | 
  •  

Pergunta

Eu sei que esta é uma pergunta estúpida. Por alguma razão, minha mente está em branco sobre este assunto. Alguma idéia?

Desculpe deveria ter sido mais clara.

Usando um HtmlGenericControl para puxar na descrição do link, bem como de imagem.

 private void InternalCreateChildControls()
    {
        if (this.DataItem != null && this.Relationships.Count > 0)
        {
            HtmlGenericControl fieldset = new HtmlGenericControl("fieldset");
            this.Controls.Add(fieldset);
            HtmlGenericControl legend = new HtmlGenericControl("legend");
            legend.InnerText = this.Caption;
            fieldset.Controls.Add(legend);

            HtmlGenericControl listControl = new HtmlGenericControl("ul");
            fieldset.Controls.Add(listControl);

            for (int i = 0; i < this.Relationships.Count; i++)
            {
                CatalogRelationshipsDataSet.CatalogRelationship relationship =
                    this.Relationships[i];

                HtmlGenericControl listItem = new HtmlGenericControl("li");
                listControl.Controls.Add(listItem);

                RelatedItemsContainer container = new RelatedItemsContainer(relationship);
                listItem.Controls.Add(container);

                Image Image = new Image();
                Image.ImageUrl = relationship.DisplayName;




                LinkButton link = new LinkButton();
                link.Text = relationship.DisplayName;



               ///ToDO Add Image or Image and description
                link.CommandName = "Redirect";
                container.Controls.Add(link);
            }
        }
    }

Não pedir a ninguém para fazer isso por mim só uma referência ou uma idéia.

Graças -overly frustrado e sentindo-se humilhado.

Foi útil?

Solução

Eu estou supondo que você deseja gerar uma imagem dynamicly com base em uma URL.

O que eu geralmente faço é um criar um muito leve HTTPHandler para servir as imagens:

using System;
using System.Web;

namespace Example
{  
    public class GetImage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString("id") != null)
            {
                // Code that uses System.Drawing to construct the image
                // ...
                context.Response.ContentType = "image/pjpeg";
                context.Response.BinaryWrite(Image);
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

Você pode fazer referência a isso diretamente em sua tag img:

<img src="GetImage.ashx?id=111"/>

Ou, você pode até mesmo criar um controle de servidor que faz isso para você:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Example.WebControl
{

    [ToolboxData("<{0}:DynamicImageCreator runat=server></{0}:DynamicImageCreator>")]
    public class DynamicImageCreator : Control
    {

        public int Id
        {
            get
            {
                if (ViewState["Id" + this.ID] == null)
                    return 0;
                else
                    return ViewState["Id"];
            }
            set
            {
                ViewState["Id" + this.ID] = value;
            }
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            output.Write("<img src='getImage.ashx?id=" + this.Id + "'/>");
            base.RenderContents(output);
        }
    }
}

Isto poderia ser usado como

<cc:DDynamicImageCreator id="db1" Id="123" runat="server/>

Outras dicas

Confira o novo controle DynamicImage lançado no CodePlex pela equipe ASP.NET.

Este é um tipo de pergunta horrível. Quer dizer, NET tem um controle de imagem onde você pode definir a fonte para o que quiser. Eu não tenho certeza o que você está querendo ser discutido.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top