English 中文(简体)
利用Pidk,从URL中获取图像?
原标题:Loading image in image view from a URL, using the iPhone sdk?

我从网上抽取许多密码,试图通过URL传送图像。 不幸的是,我所尝试的任何解决办法都没有为我工作,我有很奇怪的错误。 我正在获得图像数据,但从这个NSData没有图像。 我使用以下代码,样本为URL,并做了工作,给我以代表的形象。 然而,当我转而使用我实际的URLI时,我会遇到问题,因为它似乎也试图制造/重新塑造一个规模太大的形象。 我的守则是:

    NSString *urlString = [[[_xmlDictionary objectForKey:@"response"] objectForKey:@"movie"] objectForKey:@"poster"];   

    NSArray *parts = [urlString componentsSeparatedByString:@"""];
    urlString = [parts objectAtIndex:1];

    urlString = [urlString stringByAppendingFormat:@"/"];
    urlString = [urlString  
        stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    //NSURL * imageURL = [NSURL URLWithString:urlString];
    NSLog(@"URL:%@",urlString);
    NSURL * imageURL = [NSURL URLWithString:urlString];
    NSData * imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
    UIImage * image = [[UIImage alloc] initWithData:imageData];
    m_imageView = [[UIImageView alloc] initWithImage:image];
    m_imageView.frame = CGRectMake(10, 10,300,300);
    [self.view addSubview:m_imageView];
    [imageData release];
    [image release];

我感谢事先提供的任何帮助。

问题回答

You can convert your response from your URL to NSData and then use

NSURL *url = [NSURL URLWithString:@"<YOUR URL STRING HERE>"];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [[UIImage alloc] initWithData:data];

yourImageView.image = tmpImage;

希望这一帮助。

EDIT:

同样,为了使其工作具有工作背景,你应当称它使用read光,以便它能够打上下文所示的主线。

  [NSThread detachNewThreadSelector:@selector(downloadAndLoadImage) toTarget:self withObject:nil];

对于大量数据,你应考虑使用NSURLConnection:

NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];

NSURLConnection * conn = [NSURLConnection connectionWithRequest:request delegate:myDelegate];

这样,你就能够跟踪从服务器返回的数据:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}

页: 1 我使用的是以下代码,有不同的缩略语。 如果你提供你试图使用的<>URL,那将是有益的。

帮助跟踪这一问题的另一个想法是UIWebView,以核实你能够装载所需图像。

请尝试以下法典。 i 已测试。 劳动报酬。

//in .h file

 IBOutlet UIImageView *imgTest;

-(IBAction)buttonTapped:(id)sender;
-(void)LoadImage:(NSString *) irlString;
-(void)setImage:(NSData *) imgData;

//in .m file write the following code:

-(IBAction)buttonTapped:(id)sender
{
    [self performSelectorOnMainThread:@selector(LoadImage:) withObject:@"http://www.google.com/images/errors/logo_sm.gif" waitUntilDone:NO];
}

-(void)LoadImage:(NSString *) urlString
{
    NSURL *imgURL=[NSURL URLWithString:urlString];
    NSData *imgData=[NSData dataWithContentsOfURL:imgURL];
    [self performSelectorInBackground:@selector(setImage:) withObject:imgData];
}

-(void)setImage:(NSData *) imgData;
{
    imgTest.image=[UIImage imageWithData:imgData];
}
        NSString *img=[NSString stringWithFormat:@"https://i1.sndcdn.com/avatars-000098290475-iw9m74-large.jpg?e76cf77"];
        NSURL *url = [NSURL URLWithString:img];
        NSData *data = [[NSData alloc] initWithContentsOfURL:url];
        UIImage *img1 = [[UIImage alloc]initWithData:data];
        self.artWorksImage.image = img1;

THIS WILL HELP YOU GET THE IMAGE AND THE PARAGRAPH AND TITLE FROM YOUR WEBSITE!

如果你们想帮助你们,或获得第二形象,或者在评论中需要什么帮助,我将重写我的法典。

This is a answer quite late but I think it still might help in your future. You can go into parsing the website and that is the right way to do it but I will show you how to do it a different way, this can also be used to read xml, html, .com, anything and also, .rss so it can read RSS Feeds.
Here :

如果你要求我告诉你如何获得第二段,这可以得出你的第一个段落。 因此,如果你想获得钱,就会改变你的扫描仪,找到$。 标题是名称,但如果不告诉我,我将向你们展示如何获得第二位头衔或标题。 见下文。 我将展示如何从整个网站获得html或xml,以便你能够看到网站的全文,看一看网站读一读,然后读到该代码。 你们看到,该守则中的狗名称找到了它的标题标签或标题之下或标题之下的东西,并且根据你的需要将该代码改为整个员额,以了解所有情况。 下面是如何获取信息的主要法典。 找到如何在贵国的Log或Console上登出网站的密码。 找到自己的形象,通过国家安全监督记录仪,看像www.example.com/images/image.jpg或图像等任何图像链接。 ng或图像,或一些图像延伸,看看一下哪一部法律正在像样起作用,或者在html和xml有100个图像代码,看着该代码,然后在你的扫描器将

>改为你的代码中加以使用,然后确保只有图像的缩略语在你无光色的情况下继续缩短。

So you have

页: 1

您将使用以下扫描器,并将

<>p>>改为<media:content url:,这样可以扫描,直到静态为止,如果你知道,该部分将永远扫描到那里,然后扫描器的第二部分用<>>>>结束。

参看第一部法典的主角。 这是我们需要变革的一部分——

缩略语

        NSScanner *stringScanner2222 = [NSScanner scannerWithString:webString2222];



        NSString *content2222 = [[NSString alloc] init];




        //Change <p> to suit your need like <description> or <h1>
        [stringScanner2222 scanUpToString:@"<p>" intoString:Nil];



        [stringScanner2222 scanUpToString:@"." intoString:&content2222];







        NSString *filteredTitle = [content2222 stringByReplacingOccurrencesOfString:@"<p>" withString:@""];

        description.text = filteredTitle;

就我们而言,我们把这一部分改为:

[stringScanner2222 scanUpToString:@"<media:content url:"" intoString:Nil];
                [stringScanner2222 scanUpToString:@"">" intoString:&content2222];

如今它有ur,但扫描器的第一部分始终保持这种使用——

NSString *filteredTitle = [content2222 stringByReplacingOccurrencesOfString:@"

然后利用这一数据下载图像——

NSURL * imageURL = [NSURL URLWithString:[filteredTitle stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation([UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]])];

        UIImage * image = [UIImage imageWithData:imageData];

        [imageView setImage:image];

//This is your URL NSURL *URL = [NSURL URLWithString:@"URL HERE"]; //This is the data your pulling (dont change) NSData *data = [NSData dataWithContentsOfURL:URL];

// Assuming data is in UTF8. (dont change)
NSString *string = [NSString stringWithUTF8String:[data bytes]];
//Your textView your not done.
description.text = string;



//Do this with your textview

NSString *webStringz = description.text;



// Leave this
NSString *mastaString;
mastaString = webStringz;
{
    缩略语



    NSScanner *stringScanner2222 = [NSScanner scannerWithString:webString2222];



    NSString *content2222 = [[NSString alloc] init];




    //Change <p> to suit your need like <description> or <h1>
    [stringScanner2222 scanUpToString:@"<p>" intoString:Nil];



    [stringScanner2222 scanUpToString:@"." intoString:&content2222];







    NSString *filteredTitle = [content2222 stringByReplacingOccurrencesOfString:@"<p>" withString:@""];

    description.text = filteredTitle;


}

Title ? Same deal change the <p> to a <title> in RSS <description> and <title>. Image ? Same deal change the <p> to what ever your RSS or website uses to get a image to find But remember for both of them when you change the

“你看一看描述的关联 同样,通过重新定位,也必须改变这种状况。

因此,你必须删除这一句,并照此行事。

//This is your URL
        NSURL *URL = [NSURL URLWithString:@"URL HERE"];
        //This is the data your pulling (dont change)
        NSData *data = [NSData dataWithContentsOfURL:URL];

        // Assuming data is in UTF8. (dont change)
        NSString *string = [NSString stringWithUTF8String:[data bytes]];
        //Your textView your not done.
        description.text = string;
        NLog(@"%@", string)


        //Do this with your textview

        NSString *webStringz = description.text;



        // Leave this
        NSString *mastaString;
        mastaString = webStringz;

Now check your log it shows your whole website html or rss code then you scroll and read it and find your image link and check the code before it and change the String Scanner to your needs which is quite awesome and you have to change the stringByReplacingOccurences of.

Like I said images are a bit tricky when you do it with this method but XML Parsing is a lot easier ONCE you learn it , lol. If you request I will show you how to do it. Tell me if your having problems looking through the html or xml and specify which website again and I will look through and I will tell you how to get everything you want. Make sure :

If you want me to show you how to do it in XML just comment. If you want me to show you how to find the second paragraph or image or title or something just comment.

红十字与红新月联会

如果与我提供的守则不相干,那么,任何错误的“审慎!!!!

iii





相关问题
Using QCView and iSight to capture image

I have a QCView that loads a Quartz file which gives you iSights feedback (basically like a QTCaptureView) Everything displays fine The button simply takes a snapshot using the following simple ...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Transform rectangular image into trapezoid

In .NET how can I transform an image into a trapezoid. The Matrix class supports rotation, shear, etc, but I can t see a trapezoidal transformation. I m using the usual System.Drawing.* API, but I m ...

Rotate image through Y-axis on web page

What are my options for rotating an image on a web page through the Y-axis? I m not sure if I even have the terminology right. Is this called a rotate or a transform. Most of the searches that I ve ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

Convert from 32-BPP to 8-BPP Indexed (C#)

I need to take a full color JPG Image and remap it s colors to a Indexed palette. The palette will consist of specific colors populated from a database. I need to map each color of the image to it s "...

热门标签