Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] export map to image bug

Hi Graham:


On Wed, Jun 10, 2009 at 2:32 AM, Graham Davis<gdavis@xxxxxxxxxxxxxxx> wrote:
> I'm working on fixing a bug where exporting a map to image to a non-alpha
> image format (ie: jpeg) results in an image with a weird background colour.
>  I've narrowed down the problem to the creation of the bufferedImage
> creation in ExportMapToImageWizard.java:
>
> BufferedImage image = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_ARGB);

That sounds fine.

> This line works fine for images being exported to formats that support alpha
> (like png).  If I change the type in the above line to TYPE_INT_RGB it works
> for all image formats.

It would however:
- you may need to clear the image to a constant background color (the
map render process should do this already - it has a background color
on the map property page)
- while it would work for all image types it would not correctly
reflect PNG generation; which should use alpha should it not?

>  I'm assuming it is alright to fix this bug by simply
> changing that?  Are there any reasons that a png or other format would need
> to be saved from a bufferedImage with alpha support?

If you wanted to export an image that would be combined with others on
a web page; or even if you just wanted it transparent for copying into
a paint program or word document?

> The resulting image (as far as I can tell) is always just a composite built up from all the map
> layers into a single image anyways.

Indeed - I think the "perfect" solution would be to render the
background in the correct color - with 100% alpha - and then draw the
rest of the layers.

> Initially I was trying to determine a way to use a different bufferedImage
> type depending on if the image format it will eventually be saved to
> supports alpha, but I couldn't figure out a way to easily determine that
> short of making my own long list of all known formats and if they support
> alpha.  I didn't think this was the best solution since that list could
> change or need updating.  Is there any system built into uDig that can
> already tell what image formats support alpha or not?  If not, is simply
> changing the above type to RGB instead of ARGB an acceptable fix for this
> bug?  Thanks,

Changing it to RGB is better then what we have now; you should ask the
ImageIO guys if you can tell about alpha support when writing (I am
pretty sure you can since you can control what bands are written out
etc...). Indeed the writers are supposed to be able to figure this one
out...

Can you try with the non native jpeg writer? And check for other
reports of this problem. Also check to ensure the background of the
image was filled in with the map background color prior to drawing.

Jody


Back to the top