fbpx
Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

Fabpaint... CropBorders type functionaltiy, does it exist or alternative 07 Oct 2020 03:06 #16122

  • Sherlock's Avatar

  • Sherlock

  • Topic Author


  • Posts: 27
  • 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

    Please Log in or Create an account to join the conversation.

    Fabpaint... CropBorders type functionaltiy, does it exist or alternative 07 Oct 2020 14:43 #16128

  • Fabrice's Avatar

  • Fabrice


  • Posts: 82
  • 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

    Please Log in or Create an account to join the conversation.

    Fabpaint... CropBorders type functionaltiy, does it exist or alternative 07 Oct 2020 17:27 #16132

  • Sherlock's Avatar

  • Sherlock

  • Topic Author


  • Posts: 27
  • 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

    Please Log in or Create an account to join the conversation.

    Fabpaint... CropBorders type functionaltiy, does it exist or alternative 07 Oct 2020 23:00 #16136

  • Fabrice's Avatar

  • Fabrice


  • Posts: 82
  • 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.
    freeimage.sourceforge.io/documentation.html

    HTH,
    Fab

    Please Log in or Create an account to join the conversation.

    Fabpaint... CropBorders type functionaltiy, does it exist or alternative 14 Oct 2020 08:07 #16198

  • AlesS's Avatar

  • AlesS


  • Posts: 1
  • 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:

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1