trying to save image after modification

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    #1

    trying to save image after modification

    does anyone know why this source code throws an error??


    Dim myBitmap As System.Drawing. Bitmap
    Dim myGraphics As Graphics
    myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
    myGraphics = PictureBox1.Cre ateGraphics
    Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
    Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
    myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
    GraphicsUnit.Pi xel)
    PictureBox1.Ima ge.Save("c:\xx. tif")
    myGraphics.Disp ose()
    myBitmap.Dispos e()
    myBitmap = Nothing
    myGraphics = Nothing

  • Rad [Visual C# MVP]

    #2
    Re: trying to save image after modification

    On Sun, 08 Jul 2007 00:29:12 -0700, Joe <joe1977@tlen.p lwrote:
    >does anyone know why this source code throws an error??
    >
    >
    >Dim myBitmap As System.Drawing. Bitmap
    >Dim myGraphics As Graphics
    >myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
    >myGraphics = PictureBox1.Cre ateGraphics
    >Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
    >Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
    >myGraphics.Dra wImage(myBitmap , destRectangle1, expansionRectan gle,
    >GraphicsUnit.P ixel)
    >PictureBox1.Im age.Save("c:\xx .tif")
    >myGraphics.Dis pose()
    >myBitmap.Dispo se()
    >myBitmap = Nothing
    >myGraphics = Nothing
    What error does it throw??

    --

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: trying to save image after modification

      Joe wrote:
      does anyone know why this source code throws an error??
      >
      >
      Dim myBitmap As System.Drawing. Bitmap
      Dim myGraphics As Graphics
      myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
      myGraphics = PictureBox1.Cre ateGraphics
      That doesn't get a graphics object for the image in the picture box, it
      gets a graphics object for the screen. There is no specific
      CreateGraphics method for the picture box control, you are using the
      method inherited from the Control class.
      Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
      Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
      myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
      GraphicsUnit.Pi xel)
      PictureBox1.Ima ge.Save("c:\xx. tif")
      Have you even put an image in the picture box? There is no code for it here.
      myGraphics.Disp ose()
      myBitmap.Dispos e()
      myBitmap = Nothing
      myGraphics = Nothing
      >
      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • Joe

        #4
        Re: trying to save image after modification

        On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
        Joe wrote:
        does anyone know why this source code throws an error??
        >
        Dim myBitmap As System.Drawing. Bitmap
        Dim myGraphics As Graphics
        myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
        myGraphics = PictureBox1.Cre ateGraphics
        >
        That doesn't get a graphics object for the image in the picture box, it
        gets a graphics object for the screen. There is no specific
        CreateGraphics method for the picture box control, you are using the
        method inherited from the Control class.
        >
        Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
        Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
        myGraphics.Draw Image(myBitmap, destRectangle1, expansionRectan gle,
        GraphicsUnit.Pi xel)
        PictureBox1.Ima ge.Save("c:\xx. tif")
        >
        Have you even put an image in the picture box? There is no code for it here.
        >
        myGraphics.Disp ose()
        myBitmap.Dispos e()
        myBitmap = Nothing
        myGraphics = Nothing
        >
        --
        Göran Andersson
        _____http://www.guffa.com
        yes, the picture is displayed.
        ok, maybe I am little confused; I am just trying to load TIF file
        (whatever object it may be in), select some rectangle area and copy it
        and save it into separate TIFF file.
        how hord is it to do?


        thanks for your help.

        Comment

        • =?ISO-8859-1?Q?G=F6ran_Andersson?=

          #5
          Re: trying to save image after modification

          Joe wrote:
          On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
          >Joe wrote:
          >>does anyone know why this source code throws an error??
          >>Dim myBitmap As System.Drawing. Bitmap
          >>Dim myGraphics As Graphics
          >>myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
          >>myGraphics = PictureBox1.Cre ateGraphics
          >That doesn't get a graphics object for the image in the picture box, it
          >gets a graphics object for the screen. There is no specific
          >CreateGraphi cs method for the picture box control, you are using the
          >method inherited from the Control class.
          >>
          >>Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
          >>Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
          >>myGraphics.Dr awImage(myBitma p, destRectangle1, expansionRectan gle,
          >>GraphicsUnit. Pixel)
          >>PictureBox1.I mage.Save("c:\x x.tif")
          >Have you even put an image in the picture box? There is no code for it here.
          >>
          >>myGraphics.Di spose()
          >>myBitmap.Disp ose()
          >>myBitmap = Nothing
          >>myGraphics = Nothing
          >--
          >Göran Andersson
          >_____http://www.guffa.com
          >
          yes, the picture is displayed.
          Yes, of course it's displayed. You are drawing it on the screen where
          the picture box happens to be. It doesn't change anything about the
          picture box, though.
          ok, maybe I am little confused; I am just trying to load TIF file
          (whatever object it may be in), select some rectangle area and copy it
          and save it into separate TIFF file.
          how hord is it to do?
          Just create another Bitmap object, create a Graphics object for it and
          use that to draw on the image. Then you can save it.

          --
          Göran Andersson
          _____
          Göran Anderssons privata hemsida.

          Comment

          • Joe

            #6
            Re: trying to save image after modification

            On Jul 8, 1:40 pm, Göran Andersson <g...@guffa.com wrote:
            Joe wrote:
            On Jul 8, 8:13 am, Göran Andersson <g...@guffa.com wrote:
            Joe wrote:
            >does anyone know why this source code throws an error??
            >Dim myBitmap As System.Drawing. Bitmap
            >Dim myGraphics As Graphics
            >myBitmap = New System.Drawing. Bitmap(fileName :="C:\test.tif" )
            >myGraphics = PictureBox1.Cre ateGraphics
            That doesn't get a graphics object for the image in the picture box, it
            gets a graphics object for the screen. There is no specific
            CreateGraphics method for the picture box control, you are using the
            method inherited from the Control class.
            >
            >Dim expansionRectan gle As New Rectangle(25, 550, 1000, 350)
            >Dim destRectangle1 As New Rectangle(0, 0, 1000, 350)
            >myGraphics.Dra wImage(myBitmap , destRectangle1, expansionRectan gle,
            >GraphicsUnit.P ixel)
            >PictureBox1.Im age.Save("c:\xx .tif")
            Have you even put an image in the picture box? There is no code for ithere.
            >
            >myGraphics.Dis pose()
            >myBitmap.Dispo se()
            >myBitmap = Nothing
            >myGraphics = Nothing
            --
            Göran Andersson
            _____http://www.guffa.com
            >
            yes, the picture is displayed.
            >
            Yes, of course it's displayed. You are drawing it on the screen where
            the picture box happens to be. It doesn't change anything about the
            picture box, though.
            >
            ok, maybe I am little confused; I am just trying to load TIF file
            (whatever object it may be in), select some rectangle area and copy it
            and save it into separate TIFF file.
            how hord is it to do?
            >
            Just create another Bitmap object, create a Graphics object for it and
            use that to draw on the image. Then you can save it.
            >
            --
            Göran Andersson
            _____http://www.guffa.com- Hide quoted text -
            >
            - Show quoted text -
            thanks Goran, but how can I select rectangle from the first Bitmap
            object, copy it content and paste it to the second bitmap box?

            any ideas?

            Comment

            • =?ISO-8859-1?Q?G=F6ran_Andersson?=

              #7
              Re: trying to save image after modification

              Joe wrote:
              >>yes, the picture is displayed.
              >Yes, of course it's displayed. You are drawing it on the screen where
              >the picture box happens to be. It doesn't change anything about the
              >picture box, though.
              >>
              >>ok, maybe I am little confused; I am just trying to load TIF file
              >>(whatever object it may be in), select some rectangle area and copy it
              >>and save it into separate TIFF file.
              >>how hord is it to do?
              >Just create another Bitmap object, create a Graphics object for it and
              >use that to draw on the image. Then you can save it.
              >>
              >--
              >Göran Andersson
              >_____http://www.guffa.com- Hide quoted text -
              >>
              >- Show quoted text -
              >
              thanks Goran, but how can I select rectangle from the first Bitmap
              object, copy it content and paste it to the second bitmap box?
              >
              any ideas?
              Do as you did in the original code. Just forget about the picture box
              and use a Bitmap object.

              --
              Göran Andersson
              _____
              Göran Anderssons privata hemsida.

              Comment

              • Joe

                #8
                Re: trying to save image after modification

                On Jul 8, 4:10 pm, Göran Andersson <g...@guffa.com wrote:
                Joe wrote:
                >yes, the picture is displayed.
                Yes, of course it's displayed. You are drawing it on the screen where
                the picture box happens to be. It doesn't change anything about the
                picture box, though.
                >
                >ok, maybe I am little confused; I am just trying to load TIF file
                >(whatever object it may be in), select some rectangle area and copy it
                >and save it into separate TIFF file.
                >how hord is it to do?
                Just create another Bitmap object, create a Graphics object for it and
                use that to draw on the image. Then you can save it.
                >
                --
                Göran Andersson
                _____http://www.guffa.com-Hide quoted text -
                >
                - Show quoted text -
                >
                thanks Goran, but how can I select rectangle from the first Bitmap
                object, copy it content and paste it to the second bitmap box?
                >
                any ideas?
                >
                Do as you did in the original code. Just forget about the picture box
                and use a Bitmap object.
                >
                --
                Göran Andersson
                _____http://www.guffa.com- Hide quoted text -
                >
                - Show quoted text -

                I tried; it gives "unknown error":

                ' open test and cut a slice
                Dim myBitmap As New Bitmap("C:\TEST .TIF")
                Dim expansionRectan gle As New Rectangle(135, 10,
                myBitmap.Width, myBitmap.Height )

                Dim myGraphics As Graphics
                Dim image As Image
                Dim point As Point

                myGraphics.Draw Image(myBitmap, expansionRectan gle)
                myGraphics.Save ()
                myGraphics.Disp ose()

                ' create another bitmap
                Dim bitmap As Bitmap
                bitmap = New Bitmap(100, 100)
                Dim g As Graphics
                ' copy slice from 1. to 2.
                g = Graphics.FromIm age(bitmap)
                g.DrawImage(myB itmap, expansionRectan gle)
                g.Dispose()
                ' save to disk as 111.tif
                bitmap.Save("c: \111.tif")

                Comment

                • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                  #9
                  Re: trying to save image after modification

                  Joe wrote:
                  >Do as you did in the original code. Just forget about the picture box
                  >and use a Bitmap object.
                  >>
                  >--
                  >Göran Andersson
                  >_____http://www.guffa.com
                  >>
                  >
                  I tried; it gives "unknown error":
                  The complete error message would be helpful. That would tell where the
                  error message is coming from and where it occured.
                  ' open test and cut a slice
                  Dim myBitmap As New Bitmap("C:\TEST .TIF")
                  Dim expansionRectan gle As New Rectangle(135, 10,
                  myBitmap.Width, myBitmap.Height )
                  So far so good.
                  Dim myGraphics As Graphics
                  Dim image As Image
                  Dim point As Point
                  >
                  myGraphics.Draw Image(myBitmap, expansionRectan gle)
                  myGraphics.Save ()
                  myGraphics.Disp ose()
                  What's this code doing here? You haven't created any Image object or any
                  Graphics object, so you are just working with null references.
                  ' create another bitmap
                  Dim bitmap As Bitmap
                  bitmap = New Bitmap(100, 100)
                  Dim g As Graphics
                  ' copy slice from 1. to 2.
                  g = Graphics.FromIm age(bitmap)
                  g.DrawImage(myB itmap, expansionRectan gle)
                  g.Dispose()
                  ' save to disk as 111.tif
                  bitmap.Save("c: \111.tif")
                  That looks ok. Just remove that code in the middle, and it should work
                  just fine.

                  Don't forget to dispose the bitmaps.

                  --
                  Göran Andersson
                  _____
                  Göran Anderssons privata hemsida.

                  Comment

                  • Joe

                    #10
                    Re: trying to save image after modification

                    On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
                    That looks ok. Just remove that code in the middle, and it should work
                    just fine.
                    >
                    Don't forget to dispose the bitmaps.
                    here's the code:

                    Dim myBitmap As New Bitmap("C:\TEST .TIF")
                    Dim expansionRectan gle As New Rectangle(135, 10,
                    myBitmap.Width, myBitmap.Height )

                    Dim bitmap As Bitmap
                    bitmap = New Bitmap(100, 100)
                    Dim g As Graphics

                    g = Graphics.FromIm age(bitmap)
                    g.DrawImage(myB itmap, expansionRectan gle)
                    g.Dispose()

                    bitmap.Dispose( )

                    bitmap.Save("c: \111.tif",
                    System.Drawing. Imaging.ImageFo rmat.Tiff)


                    and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
                    "Paremeter is not Valid."


                    any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
                    format problem)


                    Comment

                    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                      #11
                      Re: trying to save image after modification

                      Joe wrote:
                      On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
                      >That looks ok. Just remove that code in the middle, and it should work
                      >just fine.
                      >>
                      >Don't forget to dispose the bitmaps.
                      >
                      here's the code:
                      >
                      Dim myBitmap As New Bitmap("C:\TEST .TIF")
                      Dim expansionRectan gle As New Rectangle(135, 10,
                      myBitmap.Width, myBitmap.Height )
                      >
                      Dim bitmap As Bitmap
                      bitmap = New Bitmap(100, 100)
                      Dim g As Graphics
                      >
                      g = Graphics.FromIm age(bitmap)
                      g.DrawImage(myB itmap, expansionRectan gle)
                      g.Dispose()
                      >
                      bitmap.Dispose( )
                      You can't save the image after you have disposed it.
                      bitmap.Save("c: \111.tif",
                      System.Drawing. Imaging.ImageFo rmat.Tiff)
                      >
                      >
                      and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
                      "Paremeter is not Valid."
                      >
                      >
                      any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
                      format problem)
                      >
                      >

                      --
                      Göran Andersson
                      _____
                      Göran Anderssons privata hemsida.

                      Comment

                      • Joe

                        #12
                        Re: trying to save image after modification

                        On Jul 9, 1:29 am, Göran Andersson <g...@guffa.com wrote:
                        Joe wrote:
                        On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
                        That looks ok. Just remove that code in the middle, and it should work
                        just fine.
                        >
                        Don't forget to dispose the bitmaps.
                        >
                        here's the code:
                        >
                        Dim myBitmap As New Bitmap("C:\TEST .TIF")
                        Dim expansionRectan gle As New Rectangle(135, 10,
                        myBitmap.Width, myBitmap.Height )
                        >
                        Dim bitmap As Bitmap
                        bitmap = New Bitmap(100, 100)
                        Dim g As Graphics
                        >
                        g = Graphics.FromIm age(bitmap)
                        g.DrawImage(myB itmap, expansionRectan gle)
                        g.Dispose()
                        >
                        bitmap.Dispose( )
                        >
                        You can't save the image after you have disposed it.
                        >
                        bitmap.Save("c: \111.tif",
                        System.Drawing. Imaging.ImageFo rmat.Tiff)
                        >
                        and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
                        "Paremeter is not Valid."
                        >
                        any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
                        format problem)
                        >
                        --
                        Göran Andersson
                        _____http://www.guffa.com- Hide quoted text -
                        >
                        - Show quoted text -
                        it's saving the empty, black box :(

                        Comment

                        • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                          #13
                          Re: trying to save image after modification

                          Joe wrote:
                          On Jul 9, 1:29 am, Göran Andersson <g...@guffa.com wrote:
                          >Joe wrote:
                          >>On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
                          >>>That looks ok. Just remove that code in the middle, and it should work
                          >>>just fine.
                          >>>Don't forget to dispose the bitmaps.
                          >>here's the code:
                          >> Dim myBitmap As New Bitmap("C:\TEST .TIF")
                          >> Dim expansionRectan gle As New Rectangle(135, 10,
                          >>myBitmap.Widt h, myBitmap.Height )
                          >> Dim bitmap As Bitmap
                          >> bitmap = New Bitmap(100, 100)
                          >> Dim g As Graphics
                          >> g = Graphics.FromIm age(bitmap)
                          >> g.DrawImage(myB itmap, expansionRectan gle)
                          >> g.Dispose()
                          >> bitmap.Dispose( )
                          >You can't save the image after you have disposed it.
                          >>
                          >> bitmap.Save("c: \111.tif",
                          >>System.Drawin g.Imaging.Image Format.Tiff)
                          >>and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
                          >>"Paremeter is not Valid."
                          >>any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
                          >>format problem)
                          >--
                          >Göran Andersson
                          >_____http://www.guffa.com- Hide quoted text -
                          >>
                          >- Show quoted text -
                          >
                          it's saving the empty, black box :(
                          >
                          Why are you drawing the image at the coordinates 135,10? That's outside
                          the 100x100 bitmap that you have created.

                          --
                          Göran Andersson
                          _____
                          Göran Anderssons privata hemsida.

                          Comment

                          • Joe

                            #14
                            Re: trying to save image after modification

                            On Jul 9, 7:52 pm, Göran Andersson <g...@guffa.com wrote:
                            Joe wrote:
                            On Jul 9, 1:29 am, Göran Andersson <g...@guffa.com wrote:
                            Joe wrote:
                            >On Jul 8, 7:30 pm, Göran Andersson <g...@guffa.com wrote:
                            >>That looks ok. Just remove that code in the middle, and it should work
                            >>just fine.
                            >>Don't forget to dispose the bitmaps.
                            >here's the code:
                            > Dim myBitmap As New Bitmap("C:\TEST .TIF")
                            > Dim expansionRectan gle As New Rectangle(135, 10,
                            >myBitmap.Width , myBitmap.Height )
                            > Dim bitmap As Bitmap
                            > bitmap = New Bitmap(100, 100)
                            > Dim g As Graphics
                            > g = Graphics.FromIm age(bitmap)
                            > g.DrawImage(myB itmap, expansionRectan gle)
                            > g.Dispose()
                            > bitmap.Dispose( )
                            You can't save the image after you have disposed it.
                            >
                            > bitmap.Save("c: \111.tif",
                            >System.Drawing .Imaging.ImageF ormat.Tiff)
                            >and error comes from the last line: bitmap.Save("c: \111.tif") ; it is
                            >"Paremeter is not Valid."
                            >any ideas?? (I've tried with Jpeg file; it is not a tiff/jpeg bitmap
                            >format problem)
                            --
                            Göran Andersson
                            _____http://www.guffa.com-Hide quoted text -
                            >
                            - Show quoted text -
                            >
                            it's saving the empty, black box :(
                            >
                            Why are you drawing the image at the coordinates 135,10? That's outside
                            the 100x100 bitmap that you have created.
                            >
                            --
                            Göran Andersson
                            _____http://www.guffa.com- Hide quoted text -
                            >
                            - Show quoted text -
                            ok, I've changed the coordinance and... you're the best! :)


                            Comment

                            Working...