I have two UIImageView's, and I want to concatenate them both to be one UIImageView. To let you know, the images have some transparency to them so you will see both of them. Als they are the same size.
If you want to overlay one imageView over another, just set its backgroundColor to clear and move it over, either using IB or directly setting its frame via code.
hey if you are using two static image-views then you can do the this by taking the screen-shot with this code
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *savedImg = UIGraphicsGetImageFromCurrentImageContext();//here is the final image
UIGraphicsEndImageContext();
[pool release];
Hope this helps.
Related
How to Implement this kind of animation in iOS objective c.
Currently I have implemented "CABasicAnimation" for this but still not able to achieve this very smoothly .
any suggestion ??
Thank you
You'll need to use Core Image with a combination of different distortion filters.
You can then animate the intensity of the filters over time.
I don't think that with CABasic animation you can obtain that. Probably is a little "movie" made by combination of CIFilterd images (check CIFilter class in the doc). Another way around (but I'm writing as I'm thinking) is mask the image somehow with a CAShapeLayer and use CAAnimation on it.
As Leena pointed out this is a simple loop of images.
Create your frames outside Xcode and then animate them this way:
NSArray *frames = [NSArray arrayWithObjects:[UIImage imageNamed:#"firstFrame.png"],
[UIImage imageNamed:#"secondFrame.png"],
// add other frames
, nil];
UIImageView *animatedImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
animatedImage.animationImages = frames;
animatedImage.animationDuration = 3.0f; // seconds
animatedImage.animationRepeatCount = 0; // 0 = loops forever
[animatedImage startAnimating];
[self.view addSubview:animatedImage];
[animatedImage release];
Why should we avoid loading a image from server while drawing a cell?
In my app I get data from server which contains image URLs as well. Now, I draw my cells and use these image URLs to fetch image from the server and draw it. Now, sometimes image does not get displayed even if image is actually present at that URL as I can see it through browser.
Is there any cell drawing limitation which could cause this issue? Shall I fetch images when I get data from server.
Does cell rendering happens before image is actually drawn.
NSString *imgUrl = [ImageURLArray objectAtIndex:indexPath.row];
if(imgUrl != nil)
{
NSString * ImagePath;
NetworkManager *manager = [[NetworkManager alloc] init];
ImagePath = [manager GetFile:imgUrl];
[manager release];
manager = nil;
if(ImagePath != nil)
{
UIImage *newImage = [UIImage imageWithData:[NSData dataWithContentsOfFile:ImagePath]];
UIGraphicsBeginImageContext(CGSizeMake(50, 50));
// now redraw our image in a smaller rectangle.
[newImage drawInRect:CGRectMake(25, 10, 30, 30)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = newImage;
}
}
return cell;
}
hope this will solve your problem
What could be happening is you have a main thread which is the UI display thread. By fetching image from a url from this thread, you are essentially blocking the cell (i.e. scrolling). Also might be the case that the image is in the process of downloading in which case you'll not see it till it downloads.
Generally UITableView does not display the cell till it's ready to be displayed, by doing the image download in the main thread you are harming your performance. What you should do is to launch a background thread which downloads the image from the url & then update the cell of the image contents when the download is ready.
Best way is to have an initial placeholder like a default image or a spinner, which gets replaced when the main image download gets done.
Dont worry you dont need to implement all this. No point in reinventing the wheel. Here's an awesome library which I use for the same - UIImageView + WebCache
fetch images when I you data from server and pass the information to the view.
like
ImageView *imageView = [[ImageView alloc] initWithNibName:#"ImageView" bundle:[NSBundle mainBundle]];
imageView.prod=self.prod;
imageView.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:imageView animated:YES];
[imageView release];
imageView=nil;
hope this will solve your problem
Clearly, the image download is taking more time. You should be using placeholder images until the download completes. You can't stop the user from scrolling.
i have a map (just an image) and i want that a user can click on some places on the map. I think i can do that with adding buttons as subviews. But i also want to animate them. So for example want to have a ring form around the link position. And this ring should animate like pulsing or so. How can i do that the best way?
greets Max
Not sure why nobody has tried to answer this but it's not too difficult.
First, create a UIImageView and configure it to animate your desired effect. The UIImageView documentation is very clear on what to do. Something like:
NSArray *imageArray = [NSArray arrayWithObjects:
[UIImage imageNamed:#"frame1.png],
[UIImage imageNamed:#"frame2.png],
...,nil];
UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:myFrame];
animatedImageView.animatedImages = imageArray;
animatedImageView.userInteractionEnabled = YES;
[self.view addSubView:animatedImageView];
[animatedImageView startAnimating];
You then have to add the code to respond to touch events on the imageView.
Alternatively, you can create a UIButton subclass that displayed an animated UIImageView per above and then use the standard addTarget:action to respond to user actions.
I have a flash file and need to reprogram for iPhone.
The design of the app is a navbar with start buttom and an image view below them. I have 46 PNL images that I want to show in succession after the start button is clicked. Each picture will stay on the screen for 5 seconds.
I tried to replicate a code that I got off of YouTube but it did not work.
For the viewcontroller.h I used the following code verbatim and was able to link images (I call them ac) to the image view and also to establish a link for the start button:
{
IBOutlet UIImageView *ac;
}
-(IBAction)startclick:(id)sender;
For the viewcontroller.m I used the following concept but I received many syntax warnings:
NSarray
List of 46 png files using #" notation for string
Last png followed by nil
Then some notation for length that each image appears.
If someone could help me out with the viewcontroller.h and viewcontroller.m to command this sort of animation, it would be much appreciated.
You should use UIImageView's animationImages property to do this, with your button calling startAnimating and/or stopAnimating:
UIImage *frame1 = [UIImage imageNamed:#"frame1.png"];
UIImage *frame2 = [UIImage imageNamed:#"frame2.png"];
UIImage *frame3 = [UIImage imageNamed:#"frame2.png"];
UIImage *frame4 = [UIImage imageNamed:#"frame2.png"];
uiImageView.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, nil];
uiImageView.animationDuration = 1.0 // defaults is number of animation images * 1/30th of a second
uiImageView.animationRepeatCount = 5; // default is 0, which repeats indefinitely
[uiImageView startAnimating];
// [uiImageView stopAnimating];
If you can't work out the syntax of Objective-C, you're going to struggle to do pretty much anything related to iPhone development.
I have an animated gif file that I want to use in my iPhone application, but the animation doesn't work. Does anybody know how to fix it?
If you have a serie of images you want to animate you can easily do it with UIImageView:
UIImage *blur5 = [UIImage imageNamed:#"blur5.png"];
UIImage *blur6 = [UIImage imageNamed:#"blur6.png"];
self.imageView.animationImages = [[NSArray alloc] initWithObjects:blur5, blur6, nil];
self.imageView.animationRepeatCount = 5;
[self.imageView startAnimating];
I found this easier than trying to use UIWebView.
UIWebView does not properly display all GIF content. You need to use a UIImageView, but the iPhone OS does not support animated GIFS and only displays the first frame.
So you need to extract all of the other frames first.
Crude example code here:
http://pliep.nl/blog/2009/04/iphone_developer_decoding_an_animated_gif_image_in_objc
You can use source at http://blog.stijnspijker.nl/2009/07/animated-and-transparent-gifs-for-iphone-made-easy/
It has a GIF decoder that you can use directly to get solution.
I successfully used it. But it have some problems with transparency.
This can be achieved by this piece of code:
NSArray * imageArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"1.png"], [UIImage imageNamed:#"2.png"], nil]; //this will be the frames of animation images in sequence.
ringImage = [[UIImageView alloc]initWithFrame:CGRectMake(100,200,600,600)];
ringImage.animationImages = imageArray;
ringImage.animationDuration = 1.5;//this the animating speed which you can modify
ringImage.contentMode = UIViewContentModeScaleAspectFill;
[ringImage startAnimating];//this method actually does the work of animating your frames.
I know its an old thread..but may be helpful for someone..:)
One other option is to decode the gif in your application, and then "frame serve" it to a OpenGL object. This way is less likely to run out of memory for large gifs.