Vote count:
0
I'm trying to draw an image on top of an existing image in a UIImageView. The new image is from a png file that I load into a UIImage. I want to display that semi-transparently. I've played around with various core graphics APIs and can't get it to work. Also, the new image is much higher resolution than the current image displayed in the UIImageView, and I also want to offset it a bit when I draw it. Can someone please point me in the right direction?
The code below is my latest version. When I call this, nothing happens. In this code, imgView is the image view I'm drawing into, and newImage is the UIImage containing the higher resolution image I want to overlay on top of the image view. Not shown is the code I also need to offset the new image, in the code below, I'm just trying to draw it at 0, 0.
UIImage* image = imgView.image;
CGRect r;
r.origin = CGPointZero;
r.size = image.size;
CGFloat scaleFactor = r.size.width * 1.0 / newImage.size.width;
UIGraphicsBeginImageContext(r.size);
// draw original image into the context
[image drawAtPoint:CGPointZero];
// get the context for CoreGraphics
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextScaleCTM(ctx, scaleFactor, -1.0 * scaleFactor);
CGContextTranslateCTM(ctx, 0, r.size.height);
CGContextBeginTransparencyLayer(ctx, nil);
CGContextSetAlpha(ctx, .25);
CGContextDrawImage(ctx, r, CGImageCreateWithImageInRect(newImage.CGImage, r));
CGContextEndTransparencyLayer(ctx);
// make image out of bitmap context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// free the context
UIGraphicsEndImageContext();
[imgView setImage: newImage];
Aucun commentaire:
Enregistrer un commentaire