How to Crop a Picture using win32 ?

Apr 19, 2011 at 10:38am
This time I am trying to make a program. Which not only allows users to load a specific image file but later also provides functionality to crop the image.

The program later sends the cropped part to the remote Socket(the easier part, which I think I will be able to do by my own).

I just need help on loading an Image to the window and cropping it.

Please Help me on this...........



Thanks in Advance,
Last edited on Apr 19, 2011 at 10:40am
Apr 19, 2011 at 6:38pm
Use GdiPlus API (windows xp or later) or use ATL::CImage class which is a wrapper around GdiPlus, but requires to have full version of Visual Studio installed.

To use GdiPlus API you could use Visual Studio Express Edition too.
Apr 21, 2011 at 8:25am
I am only restricted to use core WIN 32 API only. No MFC ,no other tools nothing ....

please tell me is there any way to achieve this....


thanks,
Apr 21, 2011 at 6:15pm
1) Load the image to a HBITMAP with LoadImage()
2) Create a new HBITMAP with the cropped dims with CreateBitmap()
3) Create two offscreen HDCs with CreateCompatibleDC(), one for each HBITMAP
4) Put each HBITMAP into an HDC with SelectObject()
5) Copy the appropriate portion of the original image to the new image with BitBlt()
6) You now have the cropped image
7) Clean up by selecting the old HBITMAPS back into the DCs with SelectObject(), then delete the DCs with DeleteDC(), then delete the bitmaps with DeleteObject()


See MSDN for details on how to use all the above functions.
Topic archived. No new replies allowed.