objective c - how to change the alpha of a groundoverlay in google maps ios sdk? -
i added groundoverlay mapview, , found thoese ways change alpha of groundoverlay.icon. how set opacity/alpha of uiimage? seems has no affect in app, still can not see map or other groundoverlays behind image. there solution handle this?
+ (uiimage *) setimage:(uiimage *)image withalpha:(cgfloat)alpha
{
// create pixel buffer in easy 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 alpha int length = height * width * 4; (int i=0; i<length; i+=4) { m_pixelbuf[i+3] = 255*alpha; } //create 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;
}
Comments
Post a Comment