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. ASP.NET read binary

ASP.NET read binary

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netgraphics
7 Posts 2 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.
  • S Offline
    S Offline
    Socheat Net
    wrote on last edited by
    #1

    Hey......... I using code below, but it not display image MemoryStream mstream = new MemoryStream(); SqlCommand cmdImg = new SqlCommand("SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'", gCnn); byte[] image = (byte[])cmdImg.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); // Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); it display as binary

    Socheat

    R 1 Reply Last reply
    0
    • S Socheat Net

      Hey......... I using code below, but it not display image MemoryStream mstream = new MemoryStream(); SqlCommand cmdImg = new SqlCommand("SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'", gCnn); byte[] image = (byte[])cmdImg.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); // Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); it display as binary

      Socheat

      R Offline
      R Offline
      Ryomin
      wrote on last edited by
      #2

      You could try something like this:

      string query = "SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'";
      SqlCommand cmdImg = new SqlCommand(query, gCnn);
      byte[] image = (byte[])cmdImg.ExecuteScalar();
      MemoryStream mstream = new MemoryStream(image);
      Bitmap bitmap = new Bitmap(System.Drawing.Image.FromStream(mstream));
      Response.ContentType = "image/gif";
      bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
      bitmap.Dispose();

      Best of luck :)

      Cheers Disgyza Programmer Analyst

      S 1 Reply Last reply
      0
      • R Ryomin

        You could try something like this:

        string query = "SELECT Image FROM TAB_Employee WHERE EmpID='" + EmpID + "'";
        SqlCommand cmdImg = new SqlCommand(query, gCnn);
        byte[] image = (byte[])cmdImg.ExecuteScalar();
        MemoryStream mstream = new MemoryStream(image);
        Bitmap bitmap = new Bitmap(System.Drawing.Image.FromStream(mstream));
        Response.ContentType = "image/gif";
        bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        bitmap.Dispose();

        Best of luck :)

        Cheers Disgyza Programmer Analyst

        S Offline
        S Offline
        Socheat Net
        wrote on last edited by
        #3

        Dear, I tried to use like what you wrote already, but my out put still the same why? Can u help me again?

        Socheat

        R 1 Reply Last reply
        0
        • S Socheat Net

          Dear, I tried to use like what you wrote already, but my out put still the same why? Can u help me again?

          Socheat

          R Offline
          R Offline
          Ryomin
          wrote on last edited by
          #4

          Ok what i think you need to do is: Place the connection code in a new WebForm and then on the page that your showing your image set the image ImageUrl property to the new webform. E.g. Image.aspx is the new webform Image.aspx contains the new code listed in the post above. WebForm1.aspx is the page with your image Set the ImageUrl property to the new webform. Image.ImageUrl = "Image.aspx"; When the ImageUrl try to load it will load the new Image.aspx page. Since you are changing the ContentType it should load the page as an Image. Let me know if this works for you, if not i'm sure there are a ton of different ways to make this work for you. Best of luck!!! :-D

          Cheers Disgyza Programmer Analyst

          S 1 Reply Last reply
          0
          • R Ryomin

            Ok what i think you need to do is: Place the connection code in a new WebForm and then on the page that your showing your image set the image ImageUrl property to the new webform. E.g. Image.aspx is the new webform Image.aspx contains the new code listed in the post above. WebForm1.aspx is the page with your image Set the ImageUrl property to the new webform. Image.ImageUrl = "Image.aspx"; When the ImageUrl try to load it will load the new Image.aspx page. Since you are changing the ContentType it should load the page as an Image. Let me know if this works for you, if not i'm sure there are a ton of different ways to make this work for you. Best of luck!!! :-D

            Cheers Disgyza Programmer Analyst

            S Offline
            S Offline
            Socheat Net
            wrote on last edited by
            #5

            Dear, I tried to use like you said Image.ImageUrl ="Image.aspx"; It does not show anyanything. Does Image.ImageUrl="Image.aspx", ImageUrl can get url?

            Socheat

            S 1 Reply Last reply
            0
            • S Socheat Net

              Dear, I tried to use like you said Image.ImageUrl ="Image.aspx"; It does not show anyanything. Does Image.ImageUrl="Image.aspx", ImageUrl can get url?

              Socheat

              S Offline
              S Offline
              Socheat Net
              wrote on last edited by
              #6

              Dear, Thank you, it work now.............

              Socheat

              R 1 Reply Last reply
              0
              • S Socheat Net

                Dear, Thank you, it work now.............

                Socheat

                R Offline
                R Offline
                Ryomin
                wrote on last edited by
                #7

                Glad to hear it :)

                Cheers Disgyza Programmer Analyst

                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