pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ajay Bhat <a.ajay.b...@gmail.com>
Subject Re: Setting Image of ImageView using Graphics2D
Date Thu, 05 Dec 2013 17:01:53 GMT
Hi,

I'm not really following this though. The goal is to set ImageView with my
Image object that I created. It's done through the loadImage() function
call as far as I can tell, but I don't understand how to pass that to an
Imageview object. Can I get some more insight/code here?


On Wed, Sep 18, 2013 at 10:18 PM, Roger and Beth Whitcomb <
RogerandBeth@rbwhitcomb.com> wrote:

>  Hi Ajay,
>     We have some code in our project that needs to combine two images into
> one, and this is a little snippet of what we do:
>
>     private static GraphicsEnvironment ge = null;
>     private static GraphicsDevice gd = null;
>     private static GraphicsConfiguration gc = null;
>
>     static {
>         ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
>         gd = ge.getDefaultScreenDevice();
>         gc = gd.getDefaultConfiguration();
>     }
>
>     /**
>      * Create an overlay image by combining the base with the overlay.
>      * <p> Assumes the overlay image will have a transparent background
> where it should
>      * let the base image show through.
>      *
>      * @param    baseImage    The basic image that will determine the size
> and type of the overlaid result.
>      * @param    overlayImage    The overlay to apply to the base image.
>      * @return            The resulting image, same type and size as the
> baseImage passed in.
>      */
>     public static BufferedImage createOverlayImage(BufferedImage
> baseImage, BufferedImage overlayImage) {
>         BufferedImage resultImage =
> gc.createCompatibleImage(baseImage.getWidth(), baseImage.getHeight(),
> Transparency.TRANSLUCENT);
>         Graphics2D graphics = resultImage.createGraphics();
>         graphics.drawImage(baseImage, 0, 0, null);
>         graphics.drawImage(overlayImage, 0, 0, null);
>         return resultImage;
>     }
>
>     /**
>      * Load an image file and convert to {@link BufferedImage} if possible.
>      *
>      * @param    imageName    The name of the image file to load.
>      * @return            If the image is a {@link Picture} then return the
>      *                {@link BufferedImage} representation of it.
>      * @throws    IllegalArgumentException if the input image is not a
> bitmap.
>      */
>     public static BufferedImage getBufferedImage(String imageName) {
>         Image img = loadImage(imageName);
>         if (img instanceof Picture) {
>         return ((Picture)img).getBufferedImage();
>         }
>         else
>         throw new IllegalArgumentException(String.format("Image '%1$s' is
> not of the proper type.", imageName));
>     }
>
>
>     /**
>      * Create an overlaid image from a base and an overlay (a state
> indicator).
>      *
>      * @param    baseName    The name of the base image file (retrieved
> from image cache
>      *                if possible.
>      * @param    overlayName    The name of the overlay image file.
>      * @return            The overlaid image, suitable for use as an icon.
>      */
>     public static Image createOverlayImage(String baseName, String
> overlayName) {
>         BufferedImage baseImage = getBufferedImage(baseName);
>         BufferedImage overlayImage = getBufferedImage(overlayName);
>         return new Picture(createOverlayImage(baseImage, overlayImage));
>     }
>
>     /** This is where we actually use the overlaid icon to set back into a
> Pivot icon. */
>     public void setIcon(boolean enabled) {
>         if (enabled) {
>         branch.setIcon(loadImage(iconName));
>         }
>         else {
>         branch.setIcon(createOverlayImage(iconName,
> "warning-overlay.gif"));
>         }
>     }
>
> Hopefully you can glean some insight out of this.  We're basically talking
> about standard Graphics2D stuff here, so not really Pivot specific.
>
> ~Roger
>
>
> On 9/18/13 2:16 AM, Ajay Bhat wrote:
>
> Hi,
>
>  I'd like to use Graphics2D to draw an image on ImageView :
>
>  <BoxPane styles="{horizontalAlignment:'center',
> verticalAlignment:'center'}">
>  <ImageView bxml:id="imgview" preferredWidth="64"
>  preferredHeight="64" styles="{fill:true}" />
>  <Label text="My Image" />
>  </BoxPane>
>
>  My code is :
>  ImageView imgview = (ImageView)
> bxmlSerializer.getNamespace().get("imgview");
> //put an image in imgview, with the graphic returned from below function
>
>    public Graphics2D makegraphic() {
>    Dimension d = new Dimension(200,200);
>     //drew a graphics object using this dimension and returned it.
> }
>
>  Can I get some help with this?
> -
>  Ajay Bhat
>
>
>


-- 
Regards,
Ajay Bhat

Mime
View raw message