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
Fabpaint... CropBorders type functionaltiy, does it exist or alternative
Fabpaint... CropBorders type functionaltiy, does it exist or alternative
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
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
fabrice(at)xsharp.eu
Fabpaint... CropBorders type functionaltiy, does it exist or alternative
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);
}
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
Fabpaint... CropBorders type functionaltiy, does it exist or alternative
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
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
fabrice(at)xsharp.eu
Fabpaint... CropBorders type functionaltiy, does it exist or alternative
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 (122.06 KiB) Viewed 640 times
-
- TestAutoCropPhotoAndResizeToStandardSize.txt
- (881 Bytes) Downloaded 96 times
-
- SSAutoCropImage.txt
- (11.54 KiB) Downloaded 96 times
-
- SSResizeOrCropImage.txt
- (14.17 KiB) Downloaded 97 times