Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] drawing image??

This topic is 5748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i create a map editor. and now i''m in progress in making selection tools but i stuck in drawing the selected image different from the others? for example i pick a fence object, and i want the fence object drawn red or transparent. is anyone know how to draw image in one color? or make the image transparent? or whatever to change the image into something different from the other thanxx

Share this post

Link to post
Share on other sites
I would create several images if I were you. After loading the fence image from disk or whatnot, create a second image using MemoryImageSource and PixelGrabber and modify the color and alpha bits to achieve the look you want.

You could also make it easier on yourself by creating a MediaManager class to handle automatic conversion and tracking of your images by use of flags for loading/getting handles/etc.

This is pre-java 1.4 stuff. I think a whole slew of new image processing capabilities were added but I stopped paying attention

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Try this:

(g must be a Graphics2D object...)

// Draw image...
g.drawImage(img, x, y, w, h, imgObserver);

// Current composite
Composite oldComp = g.getComposite();

// New composite based on alpha blending, alpha is the opacity factor.
// Range from 0.0 (100% transparent) to 1.0 (100% opaque)...
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));

// Selection rectangle color

// Draw the selection rectangle
g.fillRect(x, y, w, h);

// Restore old composite

with this code, you draw your image first and then, you draw the selection rectangle over (with some transparency)


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!