0

I have an app where the user draws pictures and then these pictures are converted to pdf. I need to be able to crop out the whitespace before conversion. Originally I kept track of the highest and lowest x and y values (http://stackoverflow.com/questions/13462088/cropping-out-whitespace-from-a-user-drawn-image). This worked for a while, but now I want to give the user the ability to erase. This is a problem because if for example the user erases the topmost point the bounding box would change, but I wouldn't the new dimensions of the box.

Right now I'm going through the entire image, pixel by pixel, to determine the bounding box. This isn't bad for one image, but I'm going to have ~70, it's way too slow for 70. I also thought about keeping every pixel in an arraylist, but I don't feel like that would work well at all.

Is there an algorithm that would help me solve this? Perhaps something already built in? Speed is more important to me than accuracy. If there is some whitespace left on each side it won't be a tragedy.

Thank you so much.

4

1 回答 1

0

您提到您正在跟踪 X 和 Y 坐标的最小值和最大值(这似乎也是您在前面的问题中选择的解决方案)。

与此类似,您应该能够从擦除事件中找到已擦除区域的最小和最大 X & Y 坐标...

当用户擦除部分图像时,您只需将擦除部分的坐标与实际图像进行比较即可找到最终坐标。

尝试查看 2 个矩形是否重叠存在一个相关问题: 确定两个矩形是否相互重叠?

您可以使用类似的逻辑(尽管略有不同)并计算出最终的最小/最大 X 和 Y 值。

于 2012-12-12T20:52:44.490 回答