I have a image and i mask this image with another image to make shape.
I just want to change the view background color of Masked image.
I am using [UIColor colorWithPatternImage:maskedImage];
But its not working.
Please suggest me how to merge or create Masked 2 images in 1 image so colorWithPatternImage will work.
UIImage *originalImage = [UIImage imageNamed:#"original.png"]; //my background image
UIImage *maskedImage = [UIImage imageNamed:#"maskedImage.png"]; //my masked image
CGSize newSize = CGSizeMake(width, height);
UIGraphicsBeginImageContext( newSize );
[originalImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
[maskedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.6];
UIImage *newMaskedBackGroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
then use this newMaskedBackGroundImage,
ex. [UIColor colorWithPatternImage:newMaskedBackGroundImage];
Are you assigning the value of
[UIColor colorWithPatternImage:maskedImage];
to anything? Like...
self.maskedView.backgroundColor = [UIColor colorWithPatternImage:maskedImage];
Related
I am resizing image but after resizing image is not returning in good quality here is my code
- (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
here is my code how it is call
UIImage *image = [self imageWithImage:self.selectedImage scaledToSize:CGSizeMake((self.imageView.image.size.width*self.slider.value), (self.imageView.image.size.height*self.slider.value))];
result of image
Here is the small image that i am scaling.
You should use UIGraphicsBeginImageContextWithOptions instead of UIGraphicsBeginImageContext.
For example,
UIGraphicsBeginImageContextWithOptions(signView.bounds.size, signView.opaque, 0.0);
[signView.layer renderInContext: UIGraphicsGetCurrentContext()];
// UIImage *imgMySignature = UIGraphicsGetImageFromCurrentImageContext();
signView.img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I am rendering image from UIView i.e signView. You can use something like this.
This is my Transparent image (Front image).
This is my selected image (Back Image).
I am giving gestures to the back image.
How can i save my image after using of pan, pinch, rotate gestures.
Present am able to combine both images but back image is saving as it is like (below image)
Using this code
CGSize newSize = CGSizeMake(640, 960);
UIGraphicsBeginImageContext( newSize);
[backImage.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
[frontImage.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];
finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(finalImage, nil, nil, nil);
I think i should handle this two lines but i don't know how to handle.
[backImage.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
[frontImage.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:1.0];
Can any one help me will highly appreciated.
Thank you.
Please find the below code to get snapshot your imageview.
UIGraphicsBeginImageContextWithOptions(yourImageViewToSnapShot.bounds.size, NO, 0.0);
[yourImageViewToSnapShot.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I have a UIImageView and I want to blur only the bottom portion of the image.
Can someone help me with this ?
I have used UIImage + ImageEffects category to blur the image completely. How can I do it for a specific portion only ?
Split your UIImage into two UIImages. Blur the one you want, leave the other one unaffected. The following splits the image exactly at the center, adjust the rects in the CGImageCreateWithImageInRect calls if you want to move the blurred portion.
UIImage *image = [UIImage imageNamed:#"yourImage.png"];
CGFloat halfImageHeight = image.size.height / 2.f;
CGImageRef topImgRef = CGImageCreateWithImageInRect(image.CGImage, CGRectMake(0, 0, image.size.width, halfImageHeight));
UIImage *topImage = [UIImage imageWithCGImage:topImgRef];
CGImageRelease(topImgRef);
CGImageRef bottomImgRef = CGImageCreateWithImageInRect(image.CGImage, CGRectMake(0, halfImageHeight, image.size.width, halfImageHeight));
UIImage *bottomImage = [UIImage imageWithCGImage:bottomImgRef];
CGImageRelease(bottomImgRef);
// Add blur effects to bottomImage
I'm currently coloring an existing image using a mask. For example, I have a white image with a black border and a circular mask (like the first two images). Then, I can create a third image with a color (i.e. green) which has green on the center of the original image (because the mask is present there).
The code I'm using is this (suggestions welcomed):
-(UIImage *)paintWithMask:(UIImage *)mask color:(UIColor *)color andSize:(CGSize)size{
UIImage *image = self;
UIImage *rotatedMask = [self rotateImage:mask]; //For some reason this is needed.
UIGraphicsBeginImageContextWithOptions(size, NO, image.scale);
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
[image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextClipToMask(context, rect, [rotatedMask CGImage]);
CGContextFillRect(context, rect);
UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return coloredImage;
}
What I need to do now is paint the green circle using only the mask (without the black border obviously), like this:
Any ideas? Thanks a lot!!
There is a much easier way of doing this without CoreGraphics. Simply do the following:
-(UIImageView *)imageViewWithMask:(UIImage *)mask color:(UIColor *)color andSize:(CGSize)size{
UIImage *tempImage = mask;
tempImage = [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIGraphicsBeginImageContextWithOptions(size, NO,0);
[tempImage drawInRect: CGRectMake(0,0,size.width,size.height)];
tempImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *iv = [[UIImageView alloc] initWithImage: tempImage];
iv.tintColor = color;
return iv;
}
hi all i have looked at answers to similar questions and none seem to work for me. I am trying to water mark an image from the camera (image in the below) and add an image and text as a water mark. The below is working perfectly for adding the image but have no idea how to do the text.
WmarkImage = [UIImage imageNamed:#"60.png"];
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
[WmarkImage drawInRect:CGRectMake(image.size.width - WmarkImage.size.width, image.size.height - WmarkImage.size.height, WmarkImage.size.width, WmarkImage.size.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imageView setImage:image];
You should convert your text to image then merge them here is an code for this please check this.
NSString* kevin = #"Hello";
UIFont* font = [UIFont systemFontOfSize:12.0f];
CGSize size = [kevin sizeWithFont:font];
// Create a bitmap context into which the text will be rendered.
UIGraphicsBeginImageContext(size);
// Render the text
[kevin drawAtPoint:CGPointMake(0.0, 0.0) withFont:font];
// Retrieve the image
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIImage *MergedImage = [UIImage imageNamed:#"mark.png"];
CGSize newSize = CGSizeMake(200, 400);
UIGraphicsBeginImageContext( newSize );
// Use existing opacity as is
[MergedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 300, 400)];
[imageView setImage:newImage];
[self.view addSubview:imageView];
This might help..
CATextLayer *theTextLayer = [CATextLayer layer];
theTextLayer.string = #"Your Text here";
theTextLayer.font = #"Helvetica";
theTextLayer.fontSize = #"12"
theTextLayer.alignmentMode = kCAAlignmentCenter;
theTextLayer.bounds = CGRectMake(0, 0, 40, 40);//give whatever width or height you want
[imageview.layer addSubLayer:theTextLayer];