Re: iphone large image downloading

2010-08-19 Thread SanthoshKumarGundu

Hi all,

I have modified my code to send asynchronous request using the below

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
 [NSURLRequest 
requestWithURL:
  [NSURL 
URLWithString:strURL]] delegate:self];

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

{   
[self.activeDownload appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Set appIcon and clear temporary data/image

UIImage *image = [[UIImage alloc]  
initWithData:self.activeDownload];


if (image != nil)
{
self.appRecord.appIcon = image;
}
else
{
	self.appRecord.appIcon = [UIImage  
imageNamed:@image_not_available.png];

}
[image release];

// Release the connection now that it's finished
self.imageConnection = nil;

// call our delegate and tell it that our icon is ready for display
[delegate appImageDidLoad:self.indexPathInTableView];
[delegate appSingleImageDidLoad:rowNumber];

self.activeDownload = nil;

// show in the status bar that network activity is starting
[UIApplication sharedApplication].networkActivityIndicatorVisible  
= NO;

}

In simulator I am able to run the application without any crashes.

But in device it is taking long time to download the  first image, and  
from second image the application is getting crashed.


I have seen crash reports ,  and it is  of type  low memory.

Can any one suggest me  how to handle this situation?

Also, I have overridden didReceiveMemoryWarning  and  added an  
alertview,  it is not getting called.


Thanks in advance.

Thanks,
Santhosh Kumar Gundu

On Aug 12, 2010, at 2:19 AM, David Duncan wrote:


On Aug 11, 2010, at 12:46 AM, SanthoshKumarGundu wrote:

Can any one  have an idea of  what is the maximum  image limit(size  
and resolution) in iphone?.


There are some images in web server. In my application , I am   
getting  these as NSData (one image at a time)  and displaying the  
image  using the following code


NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL  
URLWithString:imageURLString]];

UIImage *sampleImage = [UIImage imageWithData:imageData];

This is working fine for small images ( upto  1MB of size and  
resolution of 1024*1024).


But for large images ( 3MB size and resolution of 2500*2500), the  
application is getting crashed.



What kind of crash are you getting? I would bet that the exception  
code is 0x8badf00d (see TN2151 for information on what that means  
and how to read crash reports).


You are actually pretty lucky that the first version works at all,  
and I bet that if you are on a slow or broken network that it won't  
work and you will get a similar crash.


Generally any using -initWithContentsOfURL: for remote URLs will  
fail if you are trying to do so on the main thread (and if you are  
using UIKit, you are probably trying to do so on the main thread,  
like the above code).


The correct solution here is to use asynchronous networking to  
download the data and once you finish the download you can create a  
UIImage from the gathered data. Using synchronous networking (like  
you are above) is generally discouraged.

--
David Duncan




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iphone large image downloading

2010-08-19 Thread Mike Abdullah

On 19 Aug 2010, at 13:48, SanthoshKumarGundu wrote:

 Hi all,
 
 I have modified my code to send asynchronous request using the below
 
 NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
[NSURLRequest 
 requestWithURL:
 [NSURL 
 URLWithString:strURL]] delegate:self];
 
 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
 { 
[self.activeDownload appendData:data];
 }
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
 {
// Set appIcon and clear temporary data/image
   
UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
   
if (image != nil)
{
   self.appRecord.appIcon = image;
   }
else
{
   self.appRecord.appIcon = [UIImage 
 imageNamed:@image_not_available.png];
}
[image release];
   
// Release the connection now that it's finished
self.imageConnection = nil;
   
// call our delegate and tell it that our icon is ready for display
[delegate appImageDidLoad:self.indexPathInTableView];
   [delegate appSingleImageDidLoad:rowNumber];
   
   self.activeDownload = nil;
   
   // show in the status bar that network activity is starting
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 }
 
 In simulator I am able to run the application without any crashes.
 
 But in device it is taking long time to download the  first image, and from 
 second image the application is getting crashed.
 
 I have seen crash reports ,  and it is  of type  low memory.
 
 Can any one suggest me  how to handle this situation?
 
 Also, I have overridden didReceiveMemoryWarning  and  added an alertview,  
 it is not getting called.

Why did you do this? What do you think an alertview will achieve? Sounds like 
you need to get to grips with memory usage better. Instruments is great for 
that.
 
 Thanks in advance.
 
 Thanks,
 Santhosh Kumar Gundu
 
 On Aug 12, 2010, at 2:19 AM, David Duncan wrote:
 
 On Aug 11, 2010, at 12:46 AM, SanthoshKumarGundu wrote:
 
 Can any one  have an idea of  what is the maximum  image limit(size and 
 resolution) in iphone?.
 
 There are some images in web server. In my application , I am  getting  
 these as NSData (one image at a time)  and displaying the image  using the 
 following code
 
 NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL 
 URLWithString:imageURLString]];
 UIImage *sampleImage = [UIImage imageWithData:imageData];
 
 This is working fine for small images ( upto  1MB of size and resolution of 
 1024*1024).
 
 But for large images ( 3MB size and resolution of 2500*2500), the 
 application is getting crashed.
 
 
 What kind of crash are you getting? I would bet that the exception code is 
 0x8badf00d (see TN2151 for information on what that means and how to read 
 crash reports).
 
 You are actually pretty lucky that the first version works at all, and I bet 
 that if you are on a slow or broken network that it won't work and you will 
 get a similar crash.
 
 Generally any using -initWithContentsOfURL: for remote URLs will fail if you 
 are trying to do so on the main thread (and if you are using UIKit, you are 
 probably trying to do so on the main thread, like the above code).
 
 The correct solution here is to use asynchronous networking to download the 
 data and once you finish the download you can create a UIImage from the 
 gathered data. Using synchronous networking (like you are above) is 
 generally discouraged.
 --
 David Duncan
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
 
 This email sent to cocoa...@mikeabdullah.net

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iphone large image downloading

2010-08-19 Thread Shazron Abdullah
Write the image data to disk as it comes in instead of putting in a NSData, so 
that you don't need to put it all in memory.
Use NSFileHandle:writeData.

On 2010-08-19, at 5:48 AM, SanthoshKumarGundu wrote:

 Hi all,
 
 I have modified my code to send asynchronous request using the below
 
 NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
[NSURLRequest 
 requestWithURL:
 [NSURL 
 URLWithString:strURL]] delegate:self];
 
 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
 { 
[self.activeDownload appendData:data];
 }
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
 {
// Set appIcon and clear temporary data/image
   
UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
   
if (image != nil)
{
   self.appRecord.appIcon = image;
   }
else
{
   self.appRecord.appIcon = [UIImage 
 imageNamed:@image_not_available.png];
}
[image release];
   
// Release the connection now that it's finished
self.imageConnection = nil;
   
// call our delegate and tell it that our icon is ready for display
[delegate appImageDidLoad:self.indexPathInTableView];
   [delegate appSingleImageDidLoad:rowNumber];
   
   self.activeDownload = nil;
   
   // show in the status bar that network activity is starting
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 }
 
 In simulator I am able to run the application without any crashes.
 
 But in device it is taking long time to download the  first image, and from 
 second image the application is getting crashed.
 
 I have seen crash reports ,  and it is  of type  low memory.
 
 Can any one suggest me  how to handle this situation?
 
 Also, I have overridden didReceiveMemoryWarning  and  added an alertview,  
 it is not getting called.
 
 Thanks in advance.
 
 Thanks,
 Santhosh Kumar Gundu
 
 On Aug 12, 2010, at 2:19 AM, David Duncan wrote:
 
 On Aug 11, 2010, at 12:46 AM, SanthoshKumarGundu wrote:
 
 Can any one  have an idea of  what is the maximum  image limit(size and 
 resolution) in iphone?.
 
 There are some images in web server. In my application , I am  getting  
 these as NSData (one image at a time)  and displaying the image  using the 
 following code
 
 NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL 
 URLWithString:imageURLString]];
 UIImage *sampleImage = [UIImage imageWithData:imageData];
 
 This is working fine for small images ( upto  1MB of size and resolution of 
 1024*1024).
 
 But for large images ( 3MB size and resolution of 2500*2500), the 
 application is getting crashed.
 
 
 What kind of crash are you getting? I would bet that the exception code is 
 0x8badf00d (see TN2151 for information on what that means and how to read 
 crash reports).
 
 You are actually pretty lucky that the first version works at all, and I bet 
 that if you are on a slow or broken network that it won't work and you will 
 get a similar crash.
 
 Generally any using -initWithContentsOfURL: for remote URLs will fail if you 
 are trying to do so on the main thread (and if you are using UIKit, you are 
 probably trying to do so on the main thread, like the above code).
 
 The correct solution here is to use asynchronous networking to download the 
 data and once you finish the download you can create a UIImage from the 
 gathered data. Using synchronous networking (like you are above) is 
 generally discouraged.
 --
 David Duncan
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/shazron%40gmail.com
 
 This email sent to shaz...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iphone large image downloading

2010-08-11 Thread David Duncan
On Aug 11, 2010, at 12:46 AM, SanthoshKumarGundu wrote:

 Can any one  have an idea of  what is the maximum  image limit(size and 
 resolution) in iphone?.
 
 There are some images in web server. In my application , I am  getting  these 
 as NSData (one image at a time)  and displaying the image  using the 
 following code
 
 NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL 
 URLWithString:imageURLString]];
 UIImage *sampleImage = [UIImage imageWithData:imageData];
 
 This is working fine for small images ( upto  1MB of size and resolution of 
 1024*1024).
 
 But for large images ( 3MB size and resolution of 2500*2500), the application 
 is getting crashed.


What kind of crash are you getting? I would bet that the exception code is 
0x8badf00d (see TN2151 for information on what that means and how to read crash 
reports).

You are actually pretty lucky that the first version works at all, and I bet 
that if you are on a slow or broken network that it won't work and you will get 
a similar crash.

Generally any using -initWithContentsOfURL: for remote URLs will fail if you 
are trying to do so on the main thread (and if you are using UIKit, you are 
probably trying to do so on the main thread, like the above code).

The correct solution here is to use asynchronous networking to download the 
data and once you finish the download you can create a UIImage from the 
gathered data. Using synchronous networking (like you are above) is generally 
discouraged.
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iphone large image downloading

2010-08-11 Thread Dave Camp
The UIImage class docs indicate you shouldn't create images larger than 1024 x 
1024. You will either need to make sure your server will never send down an 
image larger than that, or download the image and downsample it to a reasonable 
size.

Dave

On Aug 11, 2010, at 12:46 AM, SanthoshKumarGundu wrote:

 Hi,
 
 Can any one  have an idea of  what is the maximum  image limit(size and 
 resolution) in iphone?.
 
 There are some images in web server. In my application , I am  getting  these 
 as NSData (one image at a time)  and displaying the image  using the 
 following code
 
 NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL 
 URLWithString:imageURLString]];
 UIImage *sampleImage = [UIImage imageWithData:imageData];
 
 This is working fine for small images ( upto  1MB of size and resolution of 
 1024*1024).
 
 But for large images ( 3MB size and resolution of 2500*2500), the application 
 is getting crashed.
 
 Can any one advise me on this.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iphone large image downloading

2010-08-11 Thread David Duncan
On Aug 11, 2010, at 3:31 PM, Dave Camp wrote:

 The UIImage class docs indicate you shouldn't create images larger than 1024 
 x 1024. You will either need to make sure your server will never send down an 
 image larger than that, or download the image and downsample it to a 
 reasonable size.


This particular language has been relaxed somewhat. As of iOS 3, creating and 
using images larger than 1024 in either dimension should work, as long as you 
have the memory for it.

Of course, a 2.5K square image consumes about 24MB when decompressed. That 
should generally work on devices that have more built in memory, but is almost 
certain to fail on older devices that do not. But 24MB is still a huge amount 
of memory to consume on a single image that the user can't even see all at once.
--
David Duncan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com