I am new to iphone development and making an application which chooses an image from existing album. After choosing the image I want to put another View on it, or another icon(acne).
Can anyone tell me how to put another image on existing image by code????
Basically if you want to overlay two views/images you can just do it like this:
[self.view addSubview:imageview1];
[self.view addSubview:imageview2];
imageview2 lays on imageview1, because you added it later.
You want to place UIImageView or UIView on the image ?
First you need to create the ImageView with the frame of your choosen image and create another ImageView in the same way as you created first ImageView and add second ImageView to your previous ImageView. if your second ImageView size is equal to the size of first ImageView, you would not be able to see your first ImageView, because it will overlap..
If you want to add a watermark on your image try this code:
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
// This is where we resize captured image
[(UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage] drawInRect:CGRectMake(0, 0, 320, 480)];
// And add the watermark on top of it
[[UIImage imageNamed:#"Watermark.png"] drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:WATERMARK_ALPHA];
// Save the results directly to the image view property
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Related
I have uiview and i want to convert that view to image which is working quite well but when i pressed the home button of iphone and run the app again the image become zoom in .Here is my code to converting view to image.
- (UIImage *)captureView {
CGRect rect = [myview bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[myview.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
checkImage.image = [self captureView];
here this code is not wrong but you used some other object instead of whole view . i don't know but try to use that view bounds in which that whole Image display.. See my answer same like your this answer from this bellow link..
how to capture uiview top uiview
Also try with self.view instead of myView in your code.
add this code instead of your checkImage.image = [self captureView]; line..
UIImageView *imgTempHeader = [[UIImageView alloc]initWithImage:[self captureView]];
imgTempHeader.frame = self.view.frame;
[self.view addSubview:imgTempHeader];
[self.view bringSubviewToFront:imgTempHeader];
You should be creating the context in a way which uses the scale of the device:
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
Then when you display the image in the image view ensure that the content mode is set to prevent scaling.
My experience is with setting up imageViews in IB. I assume checkImage is an instance of UIImageView?
If you were displaying an image in a UIImageView and had only set the view mode to center in interface builder it would appear zoomed in if the image was large.
Have a look at this way to process your image first:
UIImage *newImage = [[UIImage alloc] initWithCGImage:myCGImageRef scale:myZoomSCale orientation:UIImageOrientationDown];
Of course you will need to give it a CGImageRef for your image. Over to you or somebody else for that.
I would like to truncate one end of a UIImageView by changing the size of the frame dynamically. Of course, if it autoresizes it won't look 'truncated', but will look shrunk. The former is the effect I would like, the latter not.
So far I've set up the UIImageView in IB and then hooked it up programmatically using IBOutlet. I then placed this in ViewDidLoad, but still get the autoresizing:
[self.stringImageView setAutoresizingMask:UIViewAutoresizingNone];
self.stringImageView.frame = CGRectMake(9.0f, 508.0f, 500.0f, 26.0f);
Any ideas how I can clip my UIImageView instead of having it resize?
EDIT 1
It should also be noted that in IB I have deselected Clip Subviews and Autoresize Subviews.
Use : stringImageView.contentMode = UIViewContentModeCenter; so the image you add to the UIImageView always keeps the same size and the same position in your view.
You need to clip the UIImage object first according to imageview's frame and then set it as image for image view. See also Cropping an UIImage
#implementation UIImage (Resize)
// Returns a copy of this image that is cropped to the given bounds.
// The bounds will be adjusted using CGRectIntegral.
// This method ignores the image's imageOrientation setting.
- (UIImage *)croppedImage:(CGRect)bounds {
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
In Interface Builder set Mode in the View Tab to "Top" or whatever it should be.
Another more efficient way to go if you only wish to make part of the image visible,
or for example animate its appearance,
is to set the content mode of the UIImageView to UIViewContentModeCenter (or any other alignment) and include it in a UIScrollView.
You will only need to change the frame of the scroll view and your image will be visually cropped without you having to create the cropped image (which would be a very high price if it is for animation purpose).
In iPhone application I want to generate a image of UIScrollView whose content size is near about 600*41000. If I use current graphic image context to capture the scroll view layer, then it only captures the visible part of the scroll view not the whole layer of that scroll view.
I am using the below code:
{
UIGraphicsBeginImageContext(CGSizeMake(600, 4100));
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(00, 100, 710, 4100)];
img.image = viewImage;
[anotherScrollView addSubview:img];
}
Try to generate image not from UIScrollView but from its content view. When you add some views to UIScrollView with something like addSubview: they become scroll's content ones. Of course, UIScrollView can have more than one content view (just as any UIView can have more than one subview) and this case it will be more difficult to render its layer. But in case of only one subview (content view) you can use something like (contentView here is just some view, added to UIScrollView before):
[contentView.layer renderInContext:UIGraphicsGetCurrentContext()];
or:
[[[[scrollView subviews] lastObject] layer] renderInContext:UIGraphicsGetCurrentContext()];
When you want to use more than one view, it will be easier (I think) to add one more "root" view and add others as that view's subviews: so you can also use the code above.
I have an image I want to animate constantly in UIImageView. Like some image object to move left and right?
Thanks in advance.
Create the animation in a image editor (or something else if you already have the animation)
Then save each frame as an image. Create a folder in your Xcode project and import the files into it. (in the example below each frame is named "frame-x.png" where x is the frame number)
Then create an array of UIImages and set the UIImageView's animationImages property to it:
imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:#"frame-1"],
[UIImage imageNamed:#"frame-2"],
[UIImage imageNamed:#"frame-3"],
[UIImage imageNamed:#"frame-4"],
nil];
Where you have a UIImage for each frame. You then start the animation:
[imageView startAnimation];
You can also set the animationRepeatCount property of the image view.
See the UIImageView Class Reference for more details.
I'd like to show an image in an iPhone app, but the image I'm using is too big.
I'd like to scale it to fit the iPhone screen, I can't find any class to handle it.
UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: #"your_image.png"]];
view.frame = CGRectMake(0, 0, width, height);
To get the frame of the iPhone screen you can use
CGRect frame = [[UIScreen mainScreen] bounds];
In Interface Builder, select your UIImageView. From the Tools menu, select "Attribute Inspector". In the Image View Attributes palette, select "Scale to Fill" from the Mode popup. That should scale your image to fit.
My ImageView was set in IB, and I would need to show multiple images, so set the image of imageView, instead of creating ImageView for individual image.
After I set the image view frame size, I am still see the same result, the image was too big, so that only part of the image was displayed on the screen.