Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Pixel Alteration in an image/image rotation

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Pixel Alteration in an image/image rotation

    Hi, I am trying to devise a game, and I have come to a graphical snag. I have a gif image that is a spike with a black background (to avoid confusion, here it is :).
    Unfortunately, due to its nature, it has a spot in the lower-left corner that blocks another image. I think I can solve this by either taking this picture:, and rotating it, so that it would be flat at the angle I need, or I could alter the image, in java, so that each black pixel becomes transparent, which is ok, because of the game also has a black background. I would need it so that it would either only affect the area of the picture of the buffer, or it would take the image and return it as an altered image. What would be recommended to do and how can it be done?


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Pixel Alteration in an image/image rotation

    Try changing the pixels to transparent by setting there aplha value's to zero.

    public Image makeTransparent(Image im){
         BufferedImage bIm =  .... code to create buffered image
     
         int pixelColor = bIm.getRGB(x, y);
     
         int r = (c & 0x00ff0000) >> 16;
         int g = (c & 0x0000ff00) >> 8;
         int b = c & 0x000000ff;
     
         Color c = new Color(r, g, b);
     
         // Fuzzy algorithm to make a colour match that suits your needs, since they will probably not be the exact same colour.
     
         if(fuzzy returned colour match){
              // Set pixel value to a colour defined with 0 alpha
         }
     
         // repeat
     
         return new Image(bIm.getGraphics());
    }

    Something like that,

    Regard,
    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: Pixel Alteration in an image/image rotation

    This doesn't work because there is no constructor for Image. I kept trying different things like making it an ImageIcon to return, or adding a graphic object, but it doesn't work, but I can't get it to work without crashing.

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Default Re: Pixel Alteration in an image/image rotation

    I found a website that explains how to make one color transparent using colorFilters. Here it is.

  5. The Following User Says Thank You to bguy For This Useful Post:

    JavaPF (December 28th, 2009)

Similar Threads

  1. Blur Image
    By psrkiran in forum Algorithms & Recursion
    Replies: 10
    Last Post: December 31st, 2009, 06:57 AM
  2. Replies: 2
    Last Post: June 29th, 2009, 03:06 PM
  3. GUI problem with image in java
    By Kok in forum AWT / Java Swing
    Replies: 6
    Last Post: May 17th, 2009, 04:17 AM
  4. How images stores in awt.Image class?
    By BharatT in forum AWT / Java Swing
    Replies: 0
    Last Post: February 24th, 2009, 04:10 AM
  5. How to import an .tiff image in JSP?
    By jazz2k8 in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: May 12th, 2008, 05:55 AM

Tags for this Thread