It possible get cutout of image data.
If I know:
byte[] ImageData;
int width;
int height;
Basically I try find how get inner section of image from byte[] source.
For example I have image which is w: 1000px and h: 600px. And I want byte[] middle section 200*200px in byte[].
First of all you need to know how many bytes in your array represent one pixel. The following assumes that you have an RGB image with 3 bytes per pixel.
Then, the array-index of the first byte that represents the top-left corner of your cutout is represented as
where
yis they-coordinate of the cutout,wis the width of the entire image andxis thexcoordinate of the cutout.Then, you can do as follows:
This iterates from the first to the last row to be cut out. Then, in
i, it calculates the index of the first byte of the row in the image that should be cutout. Indestit calculates the index incutoutto which the bytes should be copied.After that it copies the bytes for the current row to be cut out into
cutoutat the specified position.I have not tested this code, really, but something like that should work. Also, please note that there’s currently no range checking – you need to make sure that the location and dimensions of the cutout are really within the bounds of the image.