0
我在地图视图中添加了地面覆盖图,并且我发现了很多不同的方法来改变groundoverlay.icon的alpha值。 How to set the opacity/alpha of a UIImage? 但它似乎没有影响的应用程序,我仍然无法看到图像背后的地图或其他groundoverlays。 有没有解决这个问题的方法?如何更改Google地图ios sdk中的地面覆盖图的alpha值?
我在地图视图中添加了地面覆盖图,并且我发现了很多不同的方法来改变groundoverlay.icon的alpha值。 How to set the opacity/alpha of a UIImage? 但它似乎没有影响的应用程序,我仍然无法看到图像背后的地图或其他groundoverlays。 有没有解决这个问题的方法?如何更改Google地图ios sdk中的地面覆盖图的alpha值?
+ (UIImage *) setImage:(UIImage *)image withAlpha:(CGFloat)alpha
{
// Create a pixel buffer in an easy to use format
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
UInt8 * m_PixelBuf = malloc(sizeof(UInt8) * height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(m_PixelBuf, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
//alter the alpha
int length = height * width * 4;
for (int i=0; i<length; i+=4)
{
m_PixelBuf[i+3] = 255*alpha;
}
//create a new image
CGContextRef ctx = CGBitmapContextCreate(m_PixelBuf, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGImageRef newImgRef = CGBitmapContextCreateImage(ctx);
CGColorSpaceRelease(colorSpace);
CGContextRelease(ctx);
free(m_PixelBuf);
UIImage *finalImage = [UIImage imageWithCGImage:newImgRef];
CGImageRelease(newImgRef);
return finalImage;
}
寻找一个解决方案自己。似乎有一个可通过JavaScript API设置的不透明选项(请参阅http://stackoverflow.com/questions/11132537/google-map-v3-png-groundoverlay-opacity),但我还没有弄清楚如何访问它通过iOS API。 – Phil