Re: Problem dealing with image transparency

From: Jess Miller <jessmiller@iswsolutions.com>
Date: Tue Jul 10 2001 - 19:54:44 EDT

I'll give that a look. Thanks Don

Don Dietrick wrote:
>
> Jess,
>
> What happens when you don't scale the image? Does the transparency
> work? I'm wondering if the smooth scaling algorithm is setting the
> transparent pixels to opaque...
>
> - Don
>
> On Tuesday, July 10, 2001, at 06:38 PM, Jess Miller wrote:
>
> > I have a layer (Don - you helped with this some time ago) that
> > allows you to "register" an image to a map using corner points.
> > The layer rescales the OMRaster (holding the image) as necessary.
> > Problem is, if the image is a GIF with transparent pixels, they
> > are turned to white by the time the image is displayed. Any ideas?
> > Here's the code for the layer:
> >
> >
> > package ipt.tas.map.openmap;
> >
> > import ipt.util.*;
> >
> > import com.bbn.openmap.*;
> > import com.bbn.openmap.event.*;
> > import com.bbn.openmap.omGraphics.*;
> > import com.bbn.openmap.proj.*;
> > import com.bbn.openmap.image.BufferedImageHelper;
> > import com.bbn.openmap.image.ImageHelper;
> >
> > import java.awt.*;
> > import java.net.*;
> > import java.awt.image.*;
> > import java.util.*;
> > import javax.swing.*;
> >
> > public class GeoRefImageLayer extends Layer
> > {
> > protected String mImageFileName;
> > protected float mULLat;
> > protected float mULLon;
> > protected float mLRLat;
> > protected float mLRLon;
> > protected OMRaster mOMRaster;
> > protected ImageIcon mImageIcon;
> > protected boolean mShowBoundingBox = false;
> > protected OMRect mOMRect;
> > protected int mLastImageHeight;
> > protected int mLastImageWidth;
> > protected int mLastX;
> > protected int mLastY;
> >
> > public GeoRefImageLayer() {
> > }
> >
> > public void setProperties(String prefix, Properties props) {
> > super.setProperties(prefix, props);
> > // get the image
> > mImageFileName = props.getProperty(prefix + ".image");
> >
> > // show coverage?
> > mShowBoundingBox = new Boolean(props.getProperty(prefix +
> > ".showBoundingBox")).booleanValue();
> > // get the upper left corner point lat/lon
> > mULLat = getFloatProperty(prefix + ".upperLeftLatitude", props);
> > mULLon = getFloatProperty(prefix + ".upperLeftLongitude",
> > props);
> > mLRLat = getFloatProperty(prefix + ".lowerRightLatitude",
> > props);
> > mLRLon = getFloatProperty(prefix + ".lowerRightLongitude",
> > props);
> > if (Debug.isEnabled(this)) {
> > Debug.println(getClass().getName() + " mULLat = " + mULLat +
> > ", mULLon = " + mULLon);
> > Debug.println(getClass().getName() + " mLRLat = " + mLRLat +
> > ", mLRLon = " + mLRLon);
> > }
> > }
> >
> > protected float getFloatProperty(String name, Properties props) {
> > try {
> > String s = props.getProperty(name);
> > if (s == null) {
> > mImageFileName = null;
> > return 0;
> > }
> > Float x = new Float(s);
> > return x.floatValue();
> > }
> > catch (Exception e) {
> > mImageFileName = null;
> > return 0;
> > }
> > }
> >
> > public void projectionChanged(ProjectionEvent evt) {
> > Projection proj = evt.getProjection();
> >
> > if (Debug.isEnabled(this)) {
> > Debug.println(getClass().getName() + ".projectionChanged
> > ");
> > }
> >
> > if (mOMRaster == null){
> > if (mImageFileName != null) {
> > try {
> > BufferedImage bi =
> > BufferedImageHelper.getBufferedImage(mImageFileName, 0, 0, -1, -1);
> > int height = bi.getHeight();
> > int width = bi.getWidth();
> >
> > PixelGrabber pg = new PixelGrabber(bi, 0, 0, width,
> > height, true);
> > int[] pixels = ImageHelper.grabPixels(pg);
> >
> > mOMRaster = new OMRaster(mULLat, mULLon, width,
> > height, pixels);
> > } catch (InterruptedException ie){
> > mOMRaster = null;
> > }
> > }
> > }
> >
> > // recompute image scaling
> > if (mOMRaster != null) {
> >
> > Point pt1 = proj.forward(mULLat, mULLon);
> > Point pt2 = proj.forward(mLRLat, mLRLon);
> >
> > int imageHeight = pt2.y - pt1.y;
> > int imageWidth = pt2.x - pt1.x;
> >
> > if (Debug.isEnabled(this)) {
> > Debug.println(getClass().getName() + " width = " +
> > imageWidth +
> > ", height = " + imageHeight);
> > }
> >
> > boolean rescaled = false;
> >
> > //if (imageWidth != mLastImageWidth || imageHeight !=
> > mLastImageHeight) {
> > mOMRaster.scaleTo(imageWidth, imageHeight,
> > OMRasterObject.SMOOTH_SCALING);
> > mLastImageWidth = imageWidth;
> > mLastImageHeight = imageHeight;
> > rescaled = true;
> > //}
> >
> > //if (rescaled || pt1.x != mLastX || pt1.y != mLastY) {
> > mOMRaster.generate(proj);
> > mLastX = pt1.x;
> > mLastY = pt1.y;
> > //}
> > }
> > if (mShowBoundingBox) {
> > if (mOMRect == null) {
> > mOMRect = new OMRect(mULLat, mULLon, mLRLat, mLRLon,
> > OMGraphic.LINETYPE_STRAIGHT);
> > }
> > mOMRect.generate(proj);
> > }
> >
> > repaint();
> > }
> >
> > public void paint(Graphics g) {
> > fireStatusUpdate(LayerStatusEvent.START_WORKING);
> > if (mOMRaster != null) {
> > mOMRaster.render(g);
> > }
> > if (mOMRect != null) {
> > mOMRect.render(g);
> > }
> > fireStatusUpdate(LayerStatusEvent.FINISH_WORKING);
> > }
> > }
> >
> > --
> > [To unsubscribe to this list send an email to "majdart@bbn.com"
> > with the following text in the BODY of the message "unsubscribe
> > openmap-users"]
> >

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Jul 10 19:49:40 2001

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:31 EDT