UIImage *image = [UIImage imageNamed:#"tick_16.png"];
CPTImage *background = [CPTImage imageWithCGImage:image.CGImage scale:image.scale];
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
imageLayer.fill = [CPTFill fillWithImage:background];
CPTAxisLabel *iconLabel = [[CPTAxisLabel alloc] initWithContentLayer:imageLayer];
iconLabel.offset = 8;
iconLabel.tickLocation = CPTDecimalFromCGFloat(location+0.5);
Image not scaling in ios7.Please give me solution. Thanks in advance
Related
I am trying to apply to filters to an image using GPUImage but i am only getting the last filter applied to the image.
Here is the code:
UIImage *inputImage = [UIImage imageNamed:#"2.jpg"];
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
//Set Brightness to 60
GPUImageBrightnessFilter *brightnessFilter = [GPUImageBrightnessFilter new];
[brightnessFilter setBrightness:2];
//Set Contrast to 12
GPUImageContrastFilter *contrastFilter = [GPUImageContrastFilter new];
[contrastFilter setContrast:1.0];
[contrastFilter addTarget:brightnessFilter];
[stillImageSource addTarget:contrastFilter];
[contrastFilter useNextFrameForImageCapture];
[stillImageSource processImage];
UIImage *outputImage1 = [contrastFilter imageFromCurrentFramebuffer];
imageView.image = outputImage1;
- (UIImage *)doctorTheImage:(UIImage *)originalImage
{
const float brownsMask[6] = {85, 255, 85, 255, 85, 255};
UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(originalImage.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor (context, 1.0,1.0, 1.0, 1);
CGContextFillRect(context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height));
CGImageRef brownRef = CGImageCreateWithMaskingColors(imageView.image.CGImage, brownsMask);
CGRect imageRect = CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
CGContextTranslateCTM(context, 0, imageView.image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
//CGImageRef whiteRef = CGImageCreateWithMaskingColors(brownRef, whiteMask);
CGContextDrawImage (context, imageRect, brownRef);
//[originalImage drawInRect:CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height)];
CGImageRelease(brownRef);
// CGImageRelease(whiteRef);
UIImage *doctoredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return doctoredImage;
}
you can try this code to change the specific range of colors defined in mask. if u
want more referance u can refer these stack overflow link : How to change the skin color of face from the source image in ios?
I'm trying to add an image to a graph using Core-Plot and I want the image to move along with the graph when it being dragged or pinched. I've tried the code below but it didn't work. Can anyone tell me how to do so?
CALayer *subLayer = [CALayer layer];
subLayer.contents = [UIImage imageNamed:#"image.png"];
subLayer.position = CGPointMake(100, 120);
[_graph addSublayer:subLayer];
Use a plot space annotation:
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageFrame];
imageLayer.fill = [CPTFill fillWithImage:[CPTImage imageNamed:#"image.png"]];
NSArray *plotPoint = #[xCoordinate, yCoordinate];
CPTPlotSpaceAnnotation *imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace
anchorPlotPoint:plotPoint];
imageAnnotation.contentLayer = imageLayer;
First of all I'm using kingpin in order to display an array of annotations. Everything works just as expected.
My question is: How can I create a custom view for an annotation?
And I'm not referring to replacing the image of MKPinAnnotationView.
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:#"cluster"];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"map_cluster"];
}
With this I'm only able to replace the default pin with an Image. But this is not all I need.
http://imgur.com/nhUIvdx
I come from an Android background where I solved this problem by inflating a layout as a cluster (aka annotation in iOS). In this XML layout I'm positioning a container (the white frame), a picture and a counter.
The result can bee seen in the picture below:
http://imgur.com/QoAQQES
How can I do this in iOS?
Thanks in advance for any suggestions!
Here you can find how to create a custom annotation:
custom annotation for maps
If you have any question, you can ask me:)
A quite late response, but I guess other people would still be interested
In a MKAnnotationView subclass:
First, define some dimensions:
#define ckImageHeight 65
#define ckImageWidth 55
#define kBorder 5
Then define the Annotation View's frame:
self.frame = CGRectMake(0, 0, ckImageWidth, ckImageHeight);
If you want the background to be an image and not just a color:
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"map_checkin"]];
Then make a placeholder for the image
CGRect checkInPictureRect = CGRectMake(kBorder, kBorder, ckImageWidth - 9 , ckImageWidth - 9);
UIView *checkInPictureView = [[UIView alloc]initWithFrame:checkInPictureRect];
Then the fun starts:
// Crop image
UIImage *croppedImage = [ImageHelper centerCropImage:image];
// Resize image
CGSize checkInPictureSize = CGSizeMake(checkInPictureRect.size.width*1.5, checkInPictureRect.size.height*1.5);
UIGraphicsBeginImageContext(checkInPictureSize);
[croppedImage drawInRect:CGRectMake(0, 0, checkInPictureRect.size.width*1.5, checkInPictureRect.size.height*1.5)];
UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc] initWithImage:resizedImage];
imageView.frame = checkInPictureView.bounds;
[checkInPictureView addSubview:imageView];
[self addSubview:checkInPictureView];
// Counter
UIView *counterView = [[UIView alloc]initWithFrame:CGRectMake(45, -2, 15, 15)];
counterView.opaque = YES;
(checkIn.isNow) ? [counterView setBackgroundColor:[UIColor enloopBlue]] : [counterView setBackgroundColor:[UIColor enloopGreen]];
counterView.layer.cornerRadius = 8;
self.counterLabel = [[UILabel alloc] init];
self.counterLabel.frame = CGRectMake(4, 2, 10, 10);
if (self.count >= 10) {
counterView.frame = CGRectMake(45, -2, 18, 18);
self.counterLabel.frame = CGRectMake(3, 3, 12, 12);
}
[self.counterLabel setTextColor:[UIColor whiteColor]];
[self.counterLabel setFont:[UIFont fontWithName: #"Trebuchet MS" size: 11.0f]];
[self.counterLabel setText:[[NSString alloc] initWithFormat:#"%lu", (unsigned long)self.count]];
[counterView addSubview:self.counterLabel];
[counterView bringSubviewToFront:self.counterLabel];
[self addSubview:counterView];
As for the centerCropImage helper, nothing special:
+ (UIImage *)centerCropImage:(UIImage *)image {
// Use smallest side length as crop square length
CGFloat squareLength = MIN(image.size.width, image.size.height);
// Center the crop area
CGRect clippedRect = CGRectMake((image.size.width - squareLength) / 2, (image.size.height - squareLength) / 2, squareLength, squareLength);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], clippedRect);
UIImage * croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
I know there are quite a few things to improve, but untill then I hope it will help others. :)
I need to put a text over an image in iPhone. It's like the Eurosport iPhone app.
(source: mzstatic.com)
In the same way I need to put a text in my app. How can I do this?
Thanks.
I found two ways
1:
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 25, 200, 200);
imageView.image = [UIImage imageNamed:#"Choice set.png"];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
myLabel.text = #"Hello There";
myLabel.textColor = [UIColor whiteColor];
myLabel.backgroundColor = [UIColor blueColor];
[imageView addSubview:myLabel];
[self.view addSubview:imageView];
[imageView release];
[myLabel release];
2:
Add text to UIImage
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
char* text= (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
CGContextSelectFont(context, "Arial",20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 0, 0, 0, 1);
CGContextShowTextAtPoint(context,10,10,text, strlen(text));
CGImageRef imgCombined = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage *retImage = [UIImage imageWithCGImage:imgCombined];
CGImageRelease(imgCombined);
return retImage;
}
then call
UIImage *image = [UIImage imageNamed:#"myimage.png"];
imageView.image = [self addText:image text:#"Hello there"];
Just simple make label with clear background.
yourLabel.backgroundColor = [UIColor clearColor];
I have an UIImage and a CGPoint which tells me in what direction I should move it to create another image. The background can be anything.
Give the initial UIImage how I can create the new one? What is the most efficient way of doing it?
Here is what I'm doing:
int originalWidth = image.size.width;
int originalHeight = image.size.height;
float xDifference = [[coords objectAtIndex:0] floatValue];
float yDifference = [[coords objectAtIndex:1] floatValue];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 240, originalWidth, originalHeight)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeTopLeft;
CGRect imageFrame = imageView.frame;
imageFrame.origin.x = xDifference;
imageFrame.origin.y = -yDifference;
imageView.frame = imageFrame;
UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Is there a more optimal version?
You can use CGImageCreateWithImageInRect(). You can get a CGImage from a UIImage with the property of the same name.
Basically what you end up doing is apply masks to the existing image to extract the portions you need. Like so -
myImageArea = CGRectMake(xOrigin, yOrigin, myWidth, myHeight);//newImage
mySubimage = CGImageCreateWithImageInRect(oldImage, myImageArea);
myRect = CGRectMake(0, 0, myWidth*2, myHeight*2);
CGContextDrawImage(context, myRect, mySubimage);
This post gives a good idea of how to use this property.