Saving a PictureBox bitmap with changes drawn...

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

    Saving a PictureBox bitmap with changes drawn...


    How do I save a PictureBox bitmap with changes
    drawn on the bitmap?
    This doesn't do it:
    PictureBox1.Ima ge.Save("key30. bmp")

  • Ken Tucker [MVP]

    #2
    Re: Saving a PictureBox bitmap with changes drawn...

    Hi,

    Dim fs As New System.IO.FileS tream("c:\key30 .bmp", IO.FileMode.Ope n)
    Dim bm As New Bitmap(fs)

    fs.Close()

    Dim g As Graphics = Graphics.FromIm age(bm)
    g.FillEllipse(B rushes.Red, 10, 10, 100, 100)

    g.Dispose()

    bm.Save("C:\key 30.bmp", Imaging.ImageFo rmat.Bmp)

    Ken
    -------------------------
    "nobody" <nonenet@nonene tcom.net> wrote in message
    news:ZAgic.1145 7$Dp7.9079@news svr31.news.prod igy.com...[color=blue]
    >
    > How do I save a PictureBox bitmap with changes
    > drawn on the bitmap?
    > This doesn't do it:
    > PictureBox1.Ima ge.Save("key30. bmp")
    >[/color]


    Comment

    • Armin Zingler

      #3
      Re: Saving a PictureBox bitmap with changes drawn...

      "nobody" <nonenet@nonene tcom.net> schrieb[color=blue]
      >
      > How do I save a PictureBox bitmap with changes
      > drawn on the bitmap?
      > This doesn't do it:
      > PictureBox1.Ima ge.Save("key30. bmp")[/color]

      Do you really paint on the bitmap assigned to the Picturebox' Image property
      or on the Picturebox?


      --
      Armin

      How to quote and why:



      Comment

      • nobody

        #4
        Re: Saving a PictureBox bitmap with changes drawn...

        Armin Zingler wrote:
        [color=blue]
        > "nobody" <nonenet@nonene tcom.net> schrieb
        >[color=green]
        >>How do I save a PictureBox bitmap with changes
        >>drawn on the bitmap?
        >>This doesn't do it:
        >>PictureBox1.I mage.Save("key3 0.bmp")[/color]
        >
        >
        > Do you really paint on the bitmap assigned to the Picturebox' Image property
        > or on the Picturebox?[/color]

        Here's what I got....

        Dim GraphicsFun As System.Drawing. Graphics
        GraphicsFun = PictureBox1.Cre ateGraphics
        Dim aFont As New System.Drawing. Font("MS Sans Serif", 11, _ FontStyle.Bold)
        Dim drawBrush As New _ System.Drawing. SolidBrush(Syst em.Drawing.Colo r.Black)
        Dim drawFormat As New System.Drawing. StringFormat

        GraphicsFun.Dra wString("E", aFont, drawBrush, 20, 31, drawFormat)

        'This draws on the picture, but when saved, it doesn't
        'save what is drawn, just saves the original loaded from file.

        Comment

        • Armin Zingler

          #5
          Re: Saving a PictureBox bitmap with changes drawn...

          "nobody" <nonenet@nonene tcom.net> schrieb[color=blue]
          > Armin Zingler wrote:
          >[color=green]
          > > "nobody" <nonenet@nonene tcom.net> schrieb
          > >[color=darkred]
          > >>How do I save a PictureBox bitmap with changes
          > >>drawn on the bitmap?
          > >>This doesn't do it:
          > >>PictureBox1.I mage.Save("key3 0.bmp")[/color]
          > >
          > >
          > > Do you really paint on the bitmap assigned to the Picturebox' Image
          > > property or on the Picturebox?[/color]
          >
          > Here's what I got....
          >
          > Dim GraphicsFun As System.Drawing. Graphics
          > GraphicsFun = PictureBox1.Cre ateGraphics
          > Dim aFont As New System.Drawing. Font("MS Sans Serif", 11, _
          > FontStyle.Bold)
          > Dim drawBrush As New _
          > System.Drawing. SolidBrush(Syst em.Drawing.Colo r.Black)
          > Dim drawFormat As New System.Drawing. StringFormat
          >
          > GraphicsFun.Dra wString("E", aFont, drawBrush, 20, 31, drawFormat)
          >
          > 'This draws on the picture, but when saved, it doesn't
          > 'save what is drawn, just saves the original loaded from file.[/color]

          You are directly drawing on the Picturebox, not on the image assigned to the
          Image property. To draw on the image:

          dim g as graphics
          g = graphics.fromim age(PictureBox1 .image)
          g.DrawString("E ", aFont, drawBrush, 20, 31, drawFormat)
          g.dispose

          If you didn't assign an image to the Image property, you must do it before.

          --
          Armin

          Comment

          • nobody

            #6
            Re: Saving a PictureBox bitmap with changes drawn...

            Armin Zingler wrote:[color=blue]
            > "nobody" <nonenet@nonene tcom.net> schrieb
            >[color=green]
            >>Armin Zingler wrote:
            >>
            >>[color=darkred]
            >>>"nobody" <nonenet@nonene tcom.net> schrieb
            >>>
            >>>
            >>>>How do I save a PictureBox bitmap with changes
            >>>>drawn on the bitmap?
            >>>>This doesn't do it:
            >>>>PictureBox1 .Image.Save("ke y30.bmp")
            >>>
            >>>
            >>>Do you really paint on the bitmap assigned to the Picturebox' Image
            >>>property or on the Picturebox?[/color]
            >>
            >>Here's what I got....
            >>
            >>Dim GraphicsFun As System.Drawing. Graphics
            >>GraphicsFun = PictureBox1.Cre ateGraphics
            >>Dim aFont As New System.Drawing. Font("MS Sans Serif", 11, _
            >>FontStyle.Bol d)
            >>Dim drawBrush As New _
            >>System.Drawin g.SolidBrush(Sy stem.Drawing.Co lor.Black)
            >>Dim drawFormat As New System.Drawing. StringFormat
            >>
            >>GraphicsFun.D rawString("E", aFont, drawBrush, 20, 31, drawFormat)
            >>
            >>'This draws on the picture, but when saved, it doesn't
            >>'save what is drawn, just saves the original loaded from file.[/color]
            >
            >
            > You are directly drawing on the Picturebox, not on the image assigned to the
            > Image property. To draw on the image:
            >
            > dim g as graphics
            > g = graphics.fromim age(PictureBox1 .image)
            > g.DrawString("E ", aFont, drawBrush, 20, 31, drawFormat)
            > g.dispose
            >
            > If you didn't assign an image to the Image property, you must do it before.[/color]

            I'm getting this error message below....

            "An unhandled exception of type 'System.Excepti on' occurred in
            system.drawing. dll
            Additional information: A Graphics object cannot be created from an
            image that has an indexed pixel format."




            Comment

            • nobody

              #7
              Re: Saving a PictureBox bitmap with changes drawn...

              nobody wrote:
              [color=blue]
              > Armin Zingler wrote:
              >[color=green]
              >> "nobody" <nonenet@nonene tcom.net> schrieb
              >>[color=darkred]
              >>> Armin Zingler wrote:
              >>>
              >>>
              >>>> "nobody" <nonenet@nonene tcom.net> schrieb
              >>>>
              >>>>
              >>>>> How do I save a PictureBox bitmap with changes
              >>>>> drawn on the bitmap?
              >>>>> This doesn't do it:
              >>>>> PictureBox1.Ima ge.Save("key30. bmp")
              >>>>
              >>>>
              >>>>
              >>>> Do you really paint on the bitmap assigned to the Picturebox' Image
              >>>> property or on the Picturebox?
              >>>
              >>>
              >>> Here's what I got....
              >>>
              >>> Dim GraphicsFun As System.Drawing. Graphics
              >>> GraphicsFun = PictureBox1.Cre ateGraphics
              >>> Dim aFont As New System.Drawing. Font("MS Sans Serif", 11, _
              >>> FontStyle.Bold)
              >>> Dim drawBrush As New _
              >>> System.Drawing. SolidBrush(Syst em.Drawing.Colo r.Black)
              >>> Dim drawFormat As New System.Drawing. StringFormat
              >>>
              >>> GraphicsFun.Dra wString("E", aFont, drawBrush, 20, 31, drawFormat)
              >>>
              >>> 'This draws on the picture, but when saved, it doesn't
              >>> 'save what is drawn, just saves the original loaded from file.[/color]
              >>
              >>
              >>
              >> You are directly drawing on the Picturebox, not on the image assigned
              >> to the
              >> Image property. To draw on the image:
              >>
              >> dim g as graphics
              >> g = graphics.fromim age(PictureBox1 .image)
              >> g.DrawString("E ", aFont, drawBrush, 20, 31, drawFormat)
              >> g.dispose
              >>
              >> If you didn't assign an image to the Image property, you must do it
              >> before.[/color]
              >
              >
              > I'm getting this error message below....
              >
              > "An unhandled exception of type 'System.Excepti on' occurred in
              > system.drawing. dll
              > Additional information: A Graphics object cannot be created from an
              > image that has an indexed pixel format."[/color]

              The line it goes to when the error occurs is....
              g.DrawString("E ", aFont, drawBrush, 20, 31, drawFormat)


              Comment

              • nobody

                #8
                Re: Saving a PictureBox bitmap with changes drawn...

                nobody wrote:[color=blue]
                >
                > How do I save a PictureBox bitmap with changes
                > drawn on the bitmap?
                > This doesn't do it:
                > PictureBox1.Ima ge.Save("key30. bmp")
                >[/color]

                Back to Delphi we go.

                Comment

                • Armin Zingler

                  #9
                  Re: Saving a PictureBox bitmap with changes drawn...

                  "nobody" <nonenet@nonene tcom.net> schrieb[color=blue]
                  >[color=green]
                  > > I'm getting this error message below....
                  > >
                  > > "An unhandled exception of type 'System.Excepti on' occurred in
                  > > system.drawing. dll
                  > > Additional information: A Graphics object cannot be created from an
                  > > image that has an indexed pixel format."[/color]
                  >
                  > The line it goes to when the error occurs is....
                  > g.DrawString("E ", aFont, drawBrush, 20, 31, drawFormat)[/color]

                  As the documentation of FromImage says, that certain formats are not
                  supported. Sorry. Do you have to have an indexed pixel format? Maybe you
                  could convert it to a Truecolor format to draw on it.


                  --
                  Armin

                  How to quote and why:



                  Comment

                  Working...