3
votes

I am using the Google Maps API. I am creating an overlay on top of the existing map.

The overlay uses UIImages, which are taken from .png images that have transparent regions.

The .PNG files are perfectly fine, and they are transparent everywhere else. But when I return them from the tileForX: Y: zoom: method of GMSSyncTile (returned as UIImages out of this method to be displayed on the map), they are no longer transparent. Now, the transparent areas are just white....!

I have spent hours trying to figure this out and I'm at my wits end. If anyone has any ideas at all I would be deeply appreciative.

Thanks!

1

1 Answers

3
votes

Yes!!!!!! I found an answer!

When you create your UIImage and you are about to return it as a tile on the map, run that image through this code:

CGSize size = [*yourImage* size];
UIGraphicsBeginImageContext(size);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
[*yourImage* drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.0);

CGContextSetLineWidth(context, 5.0);
CGContextStrokeRect(context, rect);
fixedImage =  UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return fixedImage;