Link to home
Start Free TrialLog in
Avatar of bisonguy2000
bisonguy2000Flag for United States of America

asked on

crop CImage bitmap to new Cimage

I have a CImage object that I need to extract a portion of the image to a new CImage.
I have been having trouble doing this, I saw another similar post, but there was not specific code for the solution, I am not an MFC BitBlt expert, so I really need a few lines of example code.
What I am trying to do is the following:

CImage imgOriginal;
CImage imgCrop;

imgOriginal = LoadFromResource(AfxGetInstanceHandle(),BMP_ID);  //THIS WORKS FINE
imgCrop = LoadFromResource(AfxGetInstanceHandle(),BMP_ID);  // I do this just to initialize imgCrop with a valid bitmap, although it is not currently the correct bitmap

HDC hdcCrop = imgCrop.getDC();
imgCrop =  imgOriginal.BitBlt(hdcCrop,50,50,SCRCOPY);
imgCrop.releaseDC();

//I need imageCrop to contain a subset or in this case a shifted version of the original image, but I cant get it to work


What should I be doing in my code?

THANKS!


ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bisonguy2000

ASKER

Thanks for the response. Works well.
Avatar of dasun guna
dasun guna

This works fine !!

But if I use a PNG with textual content, cropping result is not with that text content.
Why is that?

Also, how can I apply trim after cropping image?