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. Problem saving a resized image - HELP!!

Problem saving a resized image - HELP!!

Scheduled Pinned Locked Moved ASP.NET
helpgraphicsdebugging
11 Posts 5 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.
  • U User 3400231

    I now have a problem with a piece of code which worked before! My code to get an image object from a directory is: System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imgFullPath); Then I resize it as follows: System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); In the debugger, fullSizeImg and thumbNailImg are {System.Drawing.Bitmap} so they must be ok. However, when I use the following code to save the image: thumbNailImg.Save(fullPath); I get the error message: CS0103: The name 'thumbNailImg' does not exist in the current context However, if I try and save the fullSizeImg (before resizing) this works fine, so I'm totally confused and desperate for help!:confused:

    W Offline
    W Offline
    windhopper
    wrote on last edited by
    #2

    Forgive me if i'm incorrect in saying this but don't you need to create a NEW instance of the thumbNailImg first? :cool:

    "Sex is not the answer, it's the question and the answer is yes"

    U S 2 Replies Last reply
    0
    • W windhopper

      Forgive me if i'm incorrect in saying this but don't you need to create a NEW instance of the thumbNailImg first? :cool:

      "Sex is not the answer, it's the question and the answer is yes"

      U Offline
      U Offline
      User 3400231
      wrote on last edited by
      #3

      I'm a newbie to all this (so please bear with me :-)) - I found the vb version of this code on the web and attempted to rewrite as C#. I thought I was creating a new instance in this line: System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); If not, please tell me how. Many thanks Lorna

      H 1 Reply Last reply
      0
      • U User 3400231

        I'm a newbie to all this (so please bear with me :-)) - I found the vb version of this code on the web and attempted to rewrite as C#. I thought I was creating a new instance in this line: System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); If not, please tell me how. Many thanks Lorna

        H Offline
        H Offline
        Herman T Instance
        wrote on last edited by
        #4

        are they in the same method ?

        U 1 Reply Last reply
        0
        • H Herman T Instance

          are they in the same method ?

          U Offline
          U Offline
          User 3400231
          wrote on last edited by
          #5

          Yes and I'm sure it was working yesterday although I have extended my code a bit :confused:

          S 1 Reply Last reply
          0
          • W windhopper

            Forgive me if i'm incorrect in saying this but don't you need to create a NEW instance of the thumbNailImg first? :cool:

            "Sex is not the answer, it's the question and the answer is yes"

            S Offline
            S Offline
            Sherin Iranimose
            wrote on last edited by
            #6

            I dont think so, Because GetThumbnailImage returns an Image object and thumbNailImg is also an Image object. Am I right?

            EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

            1 Reply Last reply
            0
            • U User 3400231

              Yes and I'm sure it was working yesterday although I have extended my code a bit :confused:

              S Offline
              S Offline
              Sherin Iranimose
              wrote on last edited by
              #7

              can you please give the exact code(do a copy paste)?

              EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

              U 1 Reply Last reply
              0
              • S Sherin Iranimose

                can you please give the exact code(do a copy paste)?

                EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

                U Offline
                U Offline
                User 3400231
                wrote on last edited by
                #8

                I am using populating a ListBox with the files I want to resize and when the user clicks a button, the method goProcessImages is called and I traverse through each one resizing it (well I'm trying to!). Thanks - here is my code behind (sorry it's a bit of a mess but I've been commenting out things to find out what's going wrong): using System; using System.Collections; using System.Configuration; using System.Drawing; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.IO; public partial class ResizeImage : System.Web.UI.Page { ArrayList imageNames = new ArrayList(); string imagesDir = "D:\\Website\\BookImages\\"; //get path of Books dir in website protected void Page_Load(object sender, EventArgs e) { string imgForLB = ""; if (!IsPostBack) { int i = 0; try { foreach (string img in Directory.GetFiles(imagesDir, "*.jpg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.jpeg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.gif")) { imageNames.Add(img.Remove(0, 22)); } } catch { Response.Write("We are currently experiencing problems in obtaining images from the directory " + imagesDir + "Make sure you are offline and this directory exists on your laptop and it is not empty."); } //write out image names to screen for Angell to check for (i = 0; i < imageNames.Count; i++) lbFileNames.Items.Add(imageNames[i].ToString()); } } // Required by GetThumbnailImage() method, but not used public bool ThumbnailCallback() { return true; } protected void goProcessImages(object sender, EventArgs e) { string imageName = ""; //resize each file listed in listbox foreach (ListItem item in lbFileNames.Items) { imageName = item.ToString(); if (imageName != "") { //createThumbnail(imageName, 400); createThumbnail(imageName, 100); } } } protected void creat

                S 1 Reply Last reply
                0
                • U User 3400231

                  I now have a problem with a piece of code which worked before! My code to get an image object from a directory is: System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imgFullPath); Then I resize it as follows: System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); In the debugger, fullSizeImg and thumbNailImg are {System.Drawing.Bitmap} so they must be ok. However, when I use the following code to save the image: thumbNailImg.Save(fullPath); I get the error message: CS0103: The name 'thumbNailImg' does not exist in the current context However, if I try and save the fullSizeImg (before resizing) this works fine, so I'm totally confused and desperate for help!:confused:

                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #9

                  Member 3402886 wrote:

                  CS0103: The name 'thumbNailImg' does not exist in the current context

                  Show your full code.

                  Member 3402886 wrote:

                  fullSizeImg.GetThumbnailImage

                  Resizing image using GetThumbnailImage is inefficient and it returns only the thumbnail image attached to each image. So you will get pretty poorly resized image. Create a Bitmap with the new size and width, load your image into a Graphics instance, use DrawImage() to draw image into the required size. Save the bitmap. You will get image resized without loosing quality.

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                  1 Reply Last reply
                  0
                  • U User 3400231

                    I am using populating a ListBox with the files I want to resize and when the user clicks a button, the method goProcessImages is called and I traverse through each one resizing it (well I'm trying to!). Thanks - here is my code behind (sorry it's a bit of a mess but I've been commenting out things to find out what's going wrong): using System; using System.Collections; using System.Configuration; using System.Drawing; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.IO; public partial class ResizeImage : System.Web.UI.Page { ArrayList imageNames = new ArrayList(); string imagesDir = "D:\\Website\\BookImages\\"; //get path of Books dir in website protected void Page_Load(object sender, EventArgs e) { string imgForLB = ""; if (!IsPostBack) { int i = 0; try { foreach (string img in Directory.GetFiles(imagesDir, "*.jpg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.jpeg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.gif")) { imageNames.Add(img.Remove(0, 22)); } } catch { Response.Write("We are currently experiencing problems in obtaining images from the directory " + imagesDir + "Make sure you are offline and this directory exists on your laptop and it is not empty."); } //write out image names to screen for Angell to check for (i = 0; i < imageNames.Count; i++) lbFileNames.Items.Add(imageNames[i].ToString()); } } // Required by GetThumbnailImage() method, but not used public bool ThumbnailCallback() { return true; } protected void goProcessImages(object sender, EventArgs e) { string imageName = ""; //resize each file listed in listbox foreach (ListItem item in lbFileNames.Items) { imageName = item.ToString(); if (imageName != "") { //createThumbnail(imageName, 400); createThumbnail(imageName, 100); } } } protected void creat

                    S Offline
                    S Offline
                    Sherin Iranimose
                    wrote on last edited by
                    #10

                    Member 3402886 wrote:

                    try { // create the actual thumbnail image System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); }

                    Because of you are creating the variable inside try block, it is showing the error. should be like this System.Drawing.Image thumbNailImg; try { thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); }

                    EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

                    U 1 Reply Last reply
                    0
                    • S Sherin Iranimose

                      Member 3402886 wrote:

                      try { // create the actual thumbnail image System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); }

                      Because of you are creating the variable inside try block, it is showing the error. should be like this System.Drawing.Image thumbNailImg; try { thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); }

                      EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.

                      U Offline
                      U Offline
                      User 3400231
                      wrote on last edited by
                      #11

                      Thanks - tried that but get message: CS0165: Use of unassigned local variable 'thumbNailImg' on line: thumbNailImg.Save(fullPath); Thanks Lorna

                      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