1

I have a very strange problem in my app which only happen on Retina display and not simulator.

I developped a set of applications with embedded openstreetmaps tiles (pieces of map).

In each app, I have a lot of pieces of map (256px/256px) that I display in a UIScrollView. It works perfectly on non-retina devices and on retina simulator.

The problem : each tile appear with the last row of pixel in a randow color (most time it's black)

To illustrate, I made to screenshot of the same place, with device and simulator. They are grouped in one picture :

enter image description here

You can see that the black pixel line is not out of the tile, but in the tile last pixel line (cause no shift beetwen the two screens)

More strange even : sometimes, when little color variation are in the tile, the pixel line take the color of a random element, and sometimes it doesn't appear at all !

enter image description here

Here, blue line, gray lines, black lines.....

EDIT :

I simplified a lot the code, and the glitch stays with only this 2-tiles loading :

int W = 256;
int H = 256;
NSString * map1 = [[NSBundle mainBundle] pathForResource:@"test1.png" ofType:nil];
NSString * map2 = [[NSBundle mainBundle] pathForResource:@"test2.png" ofType:nil];
UIImageView * pieceOfMap1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, H*0, W, H)];
UIImageView * pieceOfMap2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, H*1, W, H)];
[pieceOfMap1 setImage:[UIImage imageWithContentsOfFile:map1]];
[pieceOfMap2 setImage:[UIImage imageWithContentsOfFile:map2]];
[self.view addSubview:pieceOfMap1];
[self.view addSubview:pieceOfMap2];

I tryed with 128x128 @2x tiles, but the problem persists !
Could it come from OpenStreetMaps images ?

My two tiles are downloadable here : http://dl.free.fr/n08C6JIqW

Martin
  • 11,881
  • 6
  • 64
  • 110
  • My tip would be to add a whole bunch of log statements where you specify tile frames and sizes. This has all the appearance of a floating point problem where you are specifying numbers that have small fractional components. – David H Jul 17 '12 at 11:55
  • Thanks for your comment. Each one of my frame operands are integer. I've logged the piece of map frames, and I've exactly the same logs with retina simulator and retina device. I rather think it would be a resizing glitch. – Martin Jul 23 '12 at 07:41
  • I made more tests, I even can reproduce the bug with a very simplified code. I edited my question. – Martin Jul 23 '12 at 08:28
  • maybe you should use floats and not ints. CGFLoat w = 250.0f; and CGRectMake(0, h*1.0f, w, h) – CarlJ Jul 23 '12 at 08:39
  • I tried that, I even logged each vars, no strange thing occured and the line stayed. – Martin Jul 23 '12 at 08:49

1 Answers1

0

Okay.

I just open the two test tiles in photoshop, made no change, then saved again in png.

The black line doesn't appear anymore.

So it comes from the open street map PNG images (to get one of them, go to http://www.openstreetmap.org/, right clic on the map, then save image)

The problem is partly explained, but now I have 2067 files to photoshop...

I googled it, but I found nothing which would explain something...

If no other explanation, i will accept my own answer, but if someone give me something to understand why, I would be glad.

Martin
  • 11,881
  • 6
  • 64
  • 110
  • The PNG format in total is quite complex - normal usage obviously is not. You have other options than PhotoShop. The Mac comes with sip, and you can easily get pngcrush and friends that operate on pngs. It could be that if you use pngcrush on the image, or use sip to convert it to jpg, that the problem also goes away. I have seen threads where there was talk of how iOS sometimes fails to accurately display PNGs what have uncommon settings in them. – David H Jul 23 '12 at 11:31
  • Yes, thanks a lot. I successfuly tried rapidoResizer, but png files are now two times bigger. I tried sips by converting the file in jpeg, but jpeg is heavier than png with these images. I did'nt succeeded to install pngcrush... – Martin Jul 23 '12 at 12:35
  • pngcrush is already installed in the Xcode app - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush – David H Jul 23 '12 at 12:58