Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
Sherlock
Posts: 60
Joined: Mon Sep 28, 2015 1:37 pm
Location: Australia mate... fare dikkum

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Post by Sherlock »

Fabrice.. hello, long time.

I have some images a lot of images that have large strip of white left and right of image content. What to strip this out and even option if there was White space at the top of image. Using say Ifranview there is a menu option called "Crop borders" which does want I want. Really would like this in Fabpaint so I can automate and resize the image.

Imagine image size which includes 3 CM of white space right and left and 1 CM on the top.

HELP...

Phil
Phil McGuinness
User avatar
Fabrice
Posts: 405
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Post by Fabrice »

Hi Phil,
nice to hear from you ! :)

Mmmm, I sure we could do it : Converting the CM to pixels might be the only problem, but based on the dpi, it should be ok.
I will check and come back

Fab
XSharp Development Team
fabrice(at)xsharp.eu
Sherlock
Posts: 60
Joined: Mon Sep 28, 2015 1:37 pm
Location: Australia mate... fare dikkum

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Post by Sherlock »

Found some code / technique if this helps. I can see the concept but not see in Fabpaint to work at a pixel level.
Thanks Fabrice..

private static BufferedImage autoCrop(BufferedImage sourceImage) {
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
boolean firstFind = true;
for (int x = 0; x < sourceImage.getWidth(); x++) {
for (int y = 0; y < sourceImage.getWidth(); y++) {
// pixel is not empty
if (sourceImage.getRGB(x, y) != 0) {

// we walk from left to right, thus x can be applied as left on first finding
if (firstFind) {
left = x;
}

// update right on each finding, because x can grow only
right = x;

// on first find apply y as top
if (firstFind) {
top = y;
} else {
// on each further find apply y to top only if a lower has been found
top = Math.min(top, y);
}

// on first find apply y as bottom
if (bottom == 0) {
bottom = y;
} else {
// on each further find apply y to bottom only if a higher has been found
bottom = Math.max(bottom, y);
}
firstFind = false;
}
}
}

return sourceImage.getSubimage(left, top, right - left, bottom - top);
}
Phil McGuinness
User avatar
Fabrice
Posts: 405
Joined: Thu Oct 08, 2015 7:47 am
Location: France

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Post by Fabrice »

Phil,
first, don't forget that FabPaint is build on top of the FreeImage library.
You will find in FabPaint an access called BitmapBits wich returns a Ptr.
From there, with the Bitmap type, you can retrieve the pixel and it's color (RGB) :
For a sample, you can get the FreeImage doc, and look at FreeImage_GetBits : This is the function used by the Access.
https://freeimage.sourceforge.io/documentation.html

HTH,
Fab
XSharp Development Team
fabrice(at)xsharp.eu
AlesS
Posts: 1
Joined: Tue May 07, 2019 6:45 am

Fabpaint... CropBorders type functionaltiy, does it exist or alternative

Post by AlesS »

I developed 2 classes that extend FabPaint ver 3.1.0.5 for VO 28. First, SSResizeOrCropImage, intelligently resizes image into some standard resolution, e.g. 1920 x 1080. If the image has different ratio of width/height, an intelligent cropping is applied. The second class SSAutoCropImage chops off white stripes on the edges of an image, if indeed they are there. I attached the source code (as plain text) of these classes and testing function, also an image on which this has been tested. Feel free to use it. The code may be portable to XSharp.
Attachments
2251I42045881566.JPG
2251I42045881566.JPG (122.06 KiB) Viewed 229 times
TestAutoCropPhotoAndResizeToStandardSize.txt
(881 Bytes) Downloaded 31 times
SSAutoCropImage.txt
(11.54 KiB) Downloaded 31 times
SSResizeOrCropImage.txt
(14.17 KiB) Downloaded 29 times
Post Reply