iPad:ImageIO:< ERROR> JPEG不是JPEG文件:以0xff 0xd9开头 [英] iPad: ImageIO: <ERROR> JPEGNot a JPEG file: starts with 0xff 0xd9

查看:927
本文介绍了iPad:ImageIO:< ERROR> JPEG不是JPEG文件:以0xff 0xd9开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问题标题中引用的错误消息让我在iPad上疯狂。

the error-message i quoted in question-title is driving me crazy on my iPad.

我正在从HTTP-Servers下载一些Jpeg-Files,并使用我的代码在iphone(iOS 5.0)上工作正常。在我的iPad(4.3)上它会发出此错误消息并且无法显示图像。

i am downloading some Jpeg-Files form HTTP-Servers, and using my code works fine on the iphone (iOS 5.0). On my iPad (4.3) it messages this error and the image cannot be displayed.

让我想知道的是我如何修复它,这对我来说并不清楚!

What makes me wonder is how i fixed it, which is not clear to me!

所以我通过NSURLConnection(conn)和NSMutableData(imageData)下载Jpeg:

So i am Downloading the Jpeg via NSURLConnection (conn) and a NSMutableData (imageData):

conn = [[NSURLConnection alloc] 
       initWithRequest:[NSURLRequest requestWithURL:[camera getJpgUrl] 
                                        cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                                    timeoutInterval:10] 
                       delegate:self 
                       startImmediately:YES];

if(conn && !imageData)
{
    imageData = [[NSMutableData data] retain];
}

委托方法是:

1)获取更多数据

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [imageData appendData:data];
}

2)拥有所有数据:

-(void)connectionDidFinishLoading:(NSURLConnection *)aConnection
{
    UIImage *img = [UIImage imageWithData:imageData];

    [imageData setLength:0];
    [conn release];
    conn = nil;

    if(img)
    {
        imageView.image=img;
    }
}

Hooray sais iphone,欢迎大喊图像。

Hooray sais the iphone, welcome yells the image.

然而,在iPad上,当我重新启动初始化NSUrlConnection的方法时,我必须释放imageData-Object而不是将其长度设置为0。我重新启动它以进行图像更新等。

On the iPad however, i have to release the imageData-Object instead of settings its length to 0 when i restart that method initializing the NSUrlConnection. i restart it for image-updates etc.

所以iPad中的代码是(只是为了总结):

So the code in iPad is (just to sum it up):

-(void)connectionDidFinishLoading:(NSURLConnection *)aConnection
{
    UIImage *img = [UIImage imageWithData:imageData];

    [imageData release];
    imagedata = [[NSMutableData data] retain];
    conn release];
    conn = nil;

    if(img)
    {
        imageView.image=img;
    }
}

所以现在,我的代码中的imageData处理是测试的结果,所以我可以改变它以移动优雅的处理。这不是那么重要。

So for now, the imageData handling in my code is a result of testing, so i could change it to have a move elegant handling. Thats not so important.

但是让我想知道的是,为什么setLength:0在ios5 / iphone4上应该做什么,但在ipad上却没有?我希望我搞砸了一些东西,但在这里我真的不明白发生了什么。

But what makes me wonder is, why does setLength:0 does what it should on ios5/iphone4, but not on ipad? i hope that i just messed up something, but here i really dont understand what is going on.

有什么想法吗?

谢谢!

推荐答案

好吧,服务器有些错误:/

okay, the server hat some bugs :/

这篇关于iPad:ImageIO:< ERROR> JPEG不是JPEG文件:以0xff 0xd9开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆