Results 1 to 4 of 4
  1. #1
    Soda is offline Member
    Join Date
    Dec 2007
    Posts
    15
    Rep Power
    0

    Default Label image Question

    How do I removed the white part of images in label?

  2. #2
    Corvin's Avatar
    Corvin is offline Member
    Join Date
    Dec 2007
    Location
    Germany
    Posts
    2
    Rep Power
    0

    Default

    The easiest way is to use a GIF-image.

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    removed the white part of images in label
    Do you mean how to remove the color white from an image? You use something like this
    Java Code:
        private BufferedImage convertToTransparent(BufferedImage src,
                                                   Color transparentColor) {
            int w = src.getWidth();
            int h = src.getHeight();
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
            BufferedImage dest = gc.createCompatibleImage(w, h, Transparency.BITMASK);
            int trgb;
            if (transparentColor != null) {
                trgb = transparentColor.getRGB() | 0xff000000;
            } else {
                trgb = 0xffff00ff;
            }
            // Copy pixels a scan line at a time
            int buf[] = new int[w];
            for (int y = 0; y < h; y++) {
                src.getRGB(0, y, w, 1, buf, 0, w);
                for (int x = 0; x < w; x++) {
                    if (buf[x] == trgb) {
                        buf[x] = 0;
                    }
                }
                dest.setRGB(0, y, w, 1, buf, 0, w);
            }
            return dest;
        }
    which you can find in your sdk (1.5) at:
    sdk1.5/src/com/sun/java/swing/plaf/windows/XPStyle

  4. #4
    Soda is offline Member
    Join Date
    Dec 2007
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Getting disk label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-05-2008, 09:07 AM
  2. Example of SWT Label
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 12:02 PM
  3. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  4. How to set an Icon in a Label?
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 12:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •