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. General Programming
  3. C / C++ / MFC
  4. Cut a bitmap under GDI+

Cut a bitmap under GDI+

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionwinforms
4 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.
  • C Offline
    C Offline
    Chen XuNuo
    wrote on last edited by
    #1

    I want to cut a bitmap and save the selection I cut what is anomalistic under GDI+.Is there any program that I can refer to? Thanks.

    M 1 Reply Last reply
    0
    • C Chen XuNuo

      I want to cut a bitmap and save the selection I cut what is anomalistic under GDI+.Is there any program that I can refer to? Thanks.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Do you mean something like this?

      // CropLeft, CropTop, CropWidth, CropHeight are INTs defining the portion of the source image
      // to copy to the new destination image

      Gdiplus::Bitmap SrcBitmap(...);
      ...
      Gdiplus::Bitmap DstBitmap(CropWidth, CropHeight, SrcBitmap.GetPixelFormat());
      Graphics DstGraphics(&DstBitmap);
      DstGraphics.DrawImage(&SrcBitmap, 0, 0, CropLeft, CropTop, CropWidth, CropHeight, UnitPixel);

      Mark

      Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        Do you mean something like this?

        // CropLeft, CropTop, CropWidth, CropHeight are INTs defining the portion of the source image
        // to copy to the new destination image

        Gdiplus::Bitmap SrcBitmap(...);
        ...
        Gdiplus::Bitmap DstBitmap(CropWidth, CropHeight, SrcBitmap.GetPixelFormat());
        Graphics DstGraphics(&DstBitmap);
        DstGraphics.DrawImage(&SrcBitmap, 0, 0, CropLeft, CropTop, CropWidth, CropHeight, UnitPixel);

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3

        C Offline
        C Offline
        Chen XuNuo
        wrote on last edited by
        #3

        I am not so familiar with GDI+,so I don't know that the code your provided can wheather achieve my purpose definitely.What I mean is the region in the bitmap is not necessarily a rect,it is mainly region that I draw with mouse.So it is a irregular region.Could you get it?;P

        M 1 Reply Last reply
        0
        • C Chen XuNuo

          I am not so familiar with GDI+,so I don't know that the code your provided can wheather achieve my purpose definitely.What I mean is the region in the bitmap is not necessarily a rect,it is mainly region that I draw with mouse.So it is a irregular region.Could you get it?;P

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Chen-XuNuo wrote:

          What I mean is the region in the bitmap is not necessarily a rect,it is mainly region that I draw with mouse.

          You could create a GraphicsPath object from the mouse points defining the outline and then use Graphics::SetClip() to set the clipping region to the GraphicsPath in the destination Graphics object before drawing the bitmap. Mark

          Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3

          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