简体   繁体   中英

How to view the UIImage via image viewer in objective-C?

I am developing in Objective-c . I have a WiFi media device and it has many image file. The WiFi media device will turn on the AP mode. So the iPhone can connect via WiFi.

After the App connect to the WiFi media device , it read the all media file that store on the WiFi media device .

I want to view the image file which on the WiFi media device but without download. I can get the Url of image file like the following:

NSURL url = http://192.72.1.1/DCIM/100_NOML/SNAP0008.JPG

I covert the url of image file to UIImage via the following code.

UIImage *urlImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:urlImage];

I want to view the UIImage via some viewer.

But how to view the UIImage in objective-C ? Which Objective-c API can view the UIImage ?

Thanks in advance.

Your code(NSURL to UIImageView) is right. But I think wrong url address.

If you check code(NSURL to UIImageView), Url change to http://static.adzerk.net/Advertisers/ca0f847878fc4be5bac353194231ef81.png

By any chance, do you miss this code? [self.view addSubview:imageView];

There is a one Apple Quick look framework available to see all type of image/documents anywhere rather than downloading those to your side and show it.

I've attached the link of Apple's quick look framework guidance here, hope this will help you definitely.

https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/UsingtheQuickLookFramework.html

Here is what I would do:

-(void)doViewImg{

    UIButton *imgViewBttn=[UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    imgViewBttn.frame=frame;
    //your img
    UIImage *urlImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
    [imgViewBttn setImage:urlImage forState:UIControlStateNormal];
    imgViewBttn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    imgViewBttn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    imgViewBttn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    imgViewBttn.backgroundColor=[UIColor blackColor];
    [imgViewBttn addTarget:self action:@selector(closeImageViewBttn:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
    [self.view addSubview: imgViewBttn];
    [urlImage release];
}

-(void)closeImageViewBttn:(id)sender{
    UIButton *imgViewBttn=(UIButton*)sender;
    [imgViewBttn removeFromSuperview];
}

It will place UIButton as big as your screen then set your image on it. Touching image (ie button) will remove it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM