简体   繁体   中英

Removing Border From HBITMAP

I have a HBITMAP which was created from using the CopyPicture method of Excel Interop. For some reason, this puts a grey border on the top and left hand edges of the image even though these are not part of the spreadsheet. Could someone tell me an easy way of removing these borders from the image. The way I thought of is getting the bits in a bytearray, removing the first row and column from this byte array and then converting the array back to a bitmap. Is there an easier or better way? Like just a simple trim function?

If you know the dimensions of the border, you can crop the bitmap by creating a copy with clone with a new bounding box applied:

int croppedWidth = x;
int croppedHeight = y;
Rectangle r = Rectangle(0, 0, croppedWidth, croppedHeight);
System::Drawing::Imaging::PixelFormat format = src->PixelFormat;
Bitmap^ result = src->Clone(r, format);

This crops the src bitmap with r and places a copy into result .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM