开发者

How do I implement code to get a live update to the displayed UIImageView?

I am trying to figure out how to take a screen capture feed and send it to an iOS device (an iPad in this case) and have the images displayed on the screen, updating as each new image is sent while clearing the old one from memory.

I am just starting with the basics, so I am trying to get the simulator to load a screenshot from the desktop and display it on the screen, and then change the image as I take a new screenshot, and either delete the old one so I can rename the new screenshot to carry the same name or to simply overwrite the old one (thus the reference should still point correctly in the programming code).

I tried using a button that reloaded my UIImageView via:

- (IBAction)buttonPressed:(id)sender
{
    [UIImageView setImage:ScreenCapture];
}

where ScreenCapture is the name of the UIImageView, with the hope that it would reload the existing referenced image.png file, but clicking the button simply exits that program within the simulator and goes back to the simulator's home screen.

Am I using the wrong object when trying to get this done via UIImageView? Is their an existing program/tutorial on this?

I would try to reverse engineer VNC for the iPhone, but both the copyright issues and the amount of advanced programming features are well beyond me.

Once I can get something working through Xcode, I am also planning on trying to implement the same thing via MonoTouch to see which language is easier to use and more beginner friendly.

Tha开发者_C百科nk you for the help, ~Chris

header:

#import <UIKit/UIKit.h>

@interface Screen_Capture_3ViewController : UIViewController {

    IBOutlet UIImageView *ScreenCapture;
    IBOutlet UIBarButtonItem *Update;
}

@property (nonatomic, retain) IBOutlet UIImageView *ScreenCapture;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *Update;

- (IBAction)buttonPressed:(id)sender;

@end

.m:

#import "Screen_Capture_3ViewController.h"

@implementation Screen_Capture_3ViewController

@synthesize ScreenCapture;
@synthesize Update;

- (IBAction)buttonPressed:(id)sender
{
    [UIImageView setImage:ScreenCapture];
}

Everything else remains at the default when selecting "View-based Application", and I connected the ScreenCapture to the UIImageView in Interface builder, as well as Update and buttonPressed to the UIBarButtonItem in Interface Builder.


setImage is an instance method, not a class method, so you can't send it directly to UIImageView (nor would it really mean much).

Keep your current code from your question for the header (but only the property should be marked as IBOutlet):

@interface Screen_Capture_3ViewController : UIViewController {

UIImageView *ScreenCapture;
UIBarButtonItem *Update;

}

@property (nonatomic, retain) IBOutlet UIImageView *ScreenCapture;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *Update;

- (IBAction)buttonPressed:(id)sender;

@end

In your implementation, your event handler should be something like this:

- (IBAction)buttonPressed:(id)sender {
    UIImage* newImage = [UIImage imageWithContentsOfFile:@"pathToImage.png"];
    [ScreenCapture setImage:newImage];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜