Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6104321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:49:42+00:00 2026-05-23T13:49:42+00:00

Most Photoshop people would know what this does, basically it re-sizes the image removing

  • 0

Most Photoshop people would know what this does, basically it re-sizes the image removing all empty space.

Is there a function in GDI+ that does something similar? Or do I have to write my own? Or if somebody has one already that would be nice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:49:43+00:00Added an answer on May 23, 2026 at 1:49 pm

    Actually, writing this wouldn’t be too terribly difficult. Being that I use Photoshop daily to design websites, and my application graphics for my own software I develop, Trim bases it off of a pixel color you select. You could do the calculation in four rectangular passes by navigating through the rows of pixels comparing their color to the color you wish to trim, storing the cordinates you are at along the way. Let me explain.

    enter image description here
    enter image description here

    Essentially what you are doing is navigating through the pixels from left to right, top to bottom, generating a Rectangle object that stores the region of (in this case) White pixels. This would be done in four passes, so you would have generated four Rectangle regions you would clip from the image.

    The logic behind the calculation is as follows (in semi-psuedo code C#)

    int x = 0, y = 0;
    Rectangle rect = new Rectangle();
    bool nonWhitePixelFound = false;
    
    for (int row = 0; row < image.Bounds.Height; row++) {
        if (!nonWhitePixelFound) {
            for (int column = 0; column = image.Bounds.Width; column++) {
                if (pixel.getColor() != Color.White) {
                    rect.Width++;
                }
                else {
                    rightBoundPixelFound = true; // Okay, we encountered a non-white pixel
                                                 // so we know we cannot trim anymore to the right
                    rect.Height--; // Since we don't want to clip the row with the non-white pixel
                    nonWhitePixelFound = true;
                    return rect; // I did not wrap this code in a function body in this example,
                                 // but to break both loops you should return, or this would be 
                                 // a rare case to use goto
                }
            }
        }
        rect.Height++; // Since we have not found a non-white pixel yet, and went through the
                       // entire row if pixels, we can go ahead and check the next row
    }
    

    You would essentially repeat this algorithm for 4 passes (4 sides of the image), until you have trimmed all the whitespace (or whatever color you need). This should work for non-traditional shaped images with scattered colors as well because of the algorithm. It stops calculating the region as soon as it detects a non-white pixel, and you should then clip that region, and perform another pass. Rinse and repeat.

    Note that I have not tested this; it is all in theory, but I wanted to provide you a general idea or approach to this other then just linking to a 3rd Party Library or component.

    Edit:

    • Here is a link that provides a similar approach with an actual code sample.
      • Automatically trim a bitmap to minimum size?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

most of the time in the service code I would have something like this:
in most code examples I see people doing this. import javax.swing.*; // for the
Most of the implementations I find require a hardware instruction to do this. However
Most people say never throw an exception out of a destructor - doing so
I know Java pretty well. I know now most of the Basics in Objective-C.
I'm trying to implement a version control system, but as most of us know
I'm making a non-rectangular dialog, modelled over an image from Photoshop (the image is
Does anyone know what is causing the sprite rollover to jump around It is
Most will recommend caching as a list. I know that is a solution and
Most folks will know the behavior of ms office applications menus: When opening a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.