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 6 of 6

Thread: Draw part of an image

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Draw part of an image

    Hey guys, I'm trying to figure out how to display only a specific part of an image, and can't figure out how to do this the way I need. Using drawImage I know I can display a rectangular part of an image, and I looked into ImageReaderParam and setting the source region, but again that only lets you choose a Rectangle, not a Polygon. I'm trying to display a single Hexagon from a larger .jpg image containing multiple hexes. If anyone can point me in the right direction, I'd appreciate it. Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Draw part of an image

    Can you paint the hex in a rectangle and then draw a polygon over it to cover up the parts you don't want to see.
    Or edit the pixels of you don't want displayed and make them transparent.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Draw part of an image

    I would like to be able to do that, I'm just not sure how. I am putting the hexes on a solid blue background in the jpg file, but I don't know what the commands are to make that transparent when I draw it. Worst case scenario, I can make one hex per jpg, but I'll still need to make the blue background transparent so only the hex appears on my Panel. I'm not too experienced with Graphics2D and AWT, so thanks for any help you can give.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Draw part of an image

    I've seen code on some of the forums that set some pixels transparent. I don't remember where.

    Perhaps you could use a photo editor to change some of the pixels to transparent.

    What is it you are trying to draw?

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Draw part of an image

    I'm making a map for a strategy game, out of hexes. I want to have each hex as a separate entity so I can build lots of maps out of the same small number of hexes, randomly generating maps with program rather than creating entire maps outside of Java. I could use photoshop to make a transparent background instead of blue. Would I need to load it into the Java program as a different file, like gif or png to get that to work? Because then I could just capture rectangles and the transparent parts can overlap.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Draw part of an image

    Write a small test program and give it a try. I've never tried to paint an image multiple times to make a grid like you seem to want to do.

Similar Threads

  1. A Part Question
    By Aksand in forum Java Theory & Questions
    Replies: 5
    Last Post: April 13th, 2011, 11:12 AM
  2. [SOLVED] Help Again Last Part of my Problem :(
    By metalx66 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 19th, 2011, 09:48 PM
  3. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  4. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 03:29 AM
  5. Paint only part of screen
    By bonus_clip in forum AWT / Java Swing
    Replies: 7
    Last Post: October 16th, 2010, 07:21 PM

Tags for this Thread