Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help with Images Required

Help with Images Required

Scheduled Pinned Locked Moved ASP.NET
csharpgraphicsquestionasp-nethelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Greenall
    wrote on last edited by
    #1

    Hi, I am writing an ASP.NET application with c# code-behind. I have a System.Drawing.Bitmap variable which funnily enough contains a bitmap image. How can I display this bitmap on an aspx page??? The standard image box will only accept an image source. Thanks Peter

    R P A 3 Replies Last reply
    0
    • P Peter Greenall

      Hi, I am writing an ASP.NET application with c# code-behind. I have a System.Drawing.Bitmap variable which funnily enough contains a bitmap image. How can I display this bitmap on an aspx page??? The standard image box will only accept an image source. Thanks Peter

      R Offline
      R Offline
      Ritwik Sanyal
      wrote on last edited by
      #2

      I think you have to store the object temporarily on the disk. I have used the following code for this you may try it:- System.Drawing.Image ObjFullImage; ObjFullImage=System.Drawing.Image.FromFile(Server.MapPath("..") + "//" + StrFile); ObjFullImage.Save(Server.MapPath("..//" + StrFile), ImageFormat.Bmp); I hope this will help you, let me know. Happy coding.:cool: I am a Software Developer using C# on ASP.NET.

      1 Reply Last reply
      0
      • P Peter Greenall

        Hi, I am writing an ASP.NET application with c# code-behind. I have a System.Drawing.Bitmap variable which funnily enough contains a bitmap image. How can I display this bitmap on an aspx page??? The standard image box will only accept an image source. Thanks Peter

        P Offline
        P Offline
        Paul Watson
        wrote on last edited by
        #3

        You can also wrap up the Bitmap in an ASPX page and reference that as the SRC for an image element. In the ASPX page you then stream the Bitmap out and the browser will display it correctly. Here is some sample code that I used (C#).

        private void Page_Load(object sender, System.EventArgs e)
        {
        long fileSize;
        FileStream filestream = new FileStream(Server.MapPath(".") + @"\tracker.jpg" ,FileMode.Open);
        fileSize = filestream.Length;

        		byte\[\] Buffer = new byte\[fileSize\];
        
        		filestream.Read(Buffer, 0, Convert.ToInt32(fileSize.ToString()));
        		filestream.Close();
        		Response.BinaryWrite(Buffer);
        

        regards, Paul Watson Bluegrass South Africa Christopher Duncan quoted: "All Corvettes are red. Everything else is just a mistake." Crikey! ain't life grand? Einstein says...

        1 Reply Last reply
        0
        • P Peter Greenall

          Hi, I am writing an ASP.NET application with c# code-behind. I have a System.Drawing.Bitmap variable which funnily enough contains a bitmap image. How can I display this bitmap on an aspx page??? The standard image box will only accept an image source. Thanks Peter

          A Offline
          A Offline
          Arjan Einbu
          wrote on last edited by
          #4

          You can stream you image to web without saving it to disk. Create an empty ASPX page, and put in something like this:

          protected override void OnLoad(System.EventArgs e)
          {
          base.OnLoad(e);

          Response.Clear();
          Response.ContentType = "image/jpeg";
          
          System.Drawing.Image image = _SomeFunctionThatGetsYourImage_(_someParametersToDecideWhichOne_);
          
          image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
          

          }

          If you are going to use this image in a webpage, you could in that webpage link to the above mentioned page with the <img src="_pagename_.aspx"> tag. (I would perhaps use a Querystring variable to tell what image to stream...)


          Have a look at my latest article about Object Prevalence with Bamboo Prevalence.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups