iPhone4分辨率获取和判断 iphone4逻辑分辨率

Here is what I've found out. Since iOS4,

[[UIScreen mainScreen]applicationFrame].size.width;and

[[UIScreen mainScreen] applicationFrame].size.height;

give measurements in "points", not "pixels". For everything else,pixels=points, but for the iPhone4, each point has 4 pixels. Normalimages are scaled in the iPhone4, so each pixel in the image ismapped onto a point. This means that the iPhone4 can run iPhoneapps without a noticeable change.

iPhone是以“点”来计量,而不是像素。一般情况,一个点 =一个像素,但是iPhone4一个点等于4个像素,所以用[[UIScreenmainScreen]applicationFrame].size.width取出来的长度和宽度还是320*480.这也意味着iPhone4跑以前的程序基本不用做什么修改。

The "apple" way to add "hi-res" images that take advantage of theiPhone's greater resolution is to replace ".png" with "@2x.png" inthe image file name, and double the pixel density (effectively,just the width&height) in the image. Importantly,don't change the way the image is referred to in your code.
iPhone4分辨率获取和判断 iphone4逻辑分辨率
So if you have "img.png" in your code, iPhone4 will load the"img@2x.png" image if it is available.

但是之前有涉及到图片的,一个像素被拉伸到了4个像素,图片质量会变低。解决方法是替换图片的后缀为"@2x.png",代码中的引用不用做任何改变,系统会根据硬件自动去读入相关文件。

The problem with this is that, if you are trying to develop aUniversal app, and include separate images for all the differentpossible screen resolutions/pixel densities, your app will getbloated pretty quick.

这样解决问题的缺点是,当你有很多图片的时候,你的程序包会有增加得很大块。

A common solution to this problem is to pull all the requiredimages of the 'net. This will make your binary nice and small. Onthe negative side, this will eat into your user's internet quota,and it willreallyannoyusers who don't have wifi--especially if your app has no otherreason to use the 'net (and you don't say your app needs the 'netin your app store description).

对于此问题一般的解决方法是将图片放到网上,运行程序时获取。当时这样也会涉及到用户上网和流量的问题。

Fortunately, I have found another way. Often, whenyouscaledownan image, the iPhone4 is clever enoughto utilise the increased pixel density of the scaled image. Forexample, you might have:

幸运的是,我找到一个另外的办法。当你缩小你的图片时,iPhone4 能聪明地帮你利用好像素,例如:

UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100.0, 50.0)];[indicatorButton setBackgroundImage:   [UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];

Now if buttonImage.png is 200x100, it will be perfectly wellbehaved on everything. Similarly, if you start with a nice 640x960(pixel) image that displays quite nicely on the iPad and you scaleit down to a 320x480 image for smaller screens, using somethinglike:

当buttonImage.png是200x100的时候,图片将完美地显示。同样的,如果你有一个640x960的,在iPad上完美显示的图片,如果你用以下代码缩小它到320x480:

+ (UIImage*)imageWithImage:(UIImage*)image newX:(float)newX newY:(float)newY
{
CGSize newSize=CGSizeMake((CGFloat)newX, (CGFloat)newY);  UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newX,newY)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return newImage;}

Itshoulddisplayquite nicely on the iPhone4. The trick is not to double-up on yourscaling. For example, if you do something like:

它在iPhone4也会很好显示。这里的技巧并不在于非得成倍地缩小。看下面的代码:

UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100.0, 50.0)];    [indicatorButton setBackgroundImage:       [Utilities imageWithImage:[UIImage imageNamed:@"buttonImage.png"] newX:100 newY:50] forState:UIControlStateNormal];

Then you'll have lost your pixel density and your image will lookall "pixely" on the iPhone4.

通过上面的代码你会得到失真的图片。

Finally, if you want to detect if you are an iPhone4 (not reallynecessary if you use the above technique), the following code maybe useful:

最后,你需要通过代码判断你的设备是否是iPhone4,请参考下面的代码:

+(bool)imAnIphone4
{
 return([[UIScreen mainScreen]respondsToSelector:@selector(scale)] && [UIScreen mainScreen].scale==2);
}

  

爱华网本文地址 » http://www.413yy.cn/a/25101015/259948.html

更多阅读

命令行下怎样释放和获取IP地址 获取ip地址命令

今天跟大家讲的就是命令提示符下获取和释放IP地址的操作,主要是针对使用DHCP来获取IP地址的用户,下面我们一起看看怎样操作吧。命令行下怎样释放和获取IP地址——工具/原料命令提示符命令行下怎样释放和获取IP地址——步骤/方法命

微博的姿态和行动的逻辑 集体行动的逻辑

微博的姿态和行动的逻辑张鸣微博存活了两年多了,各地各个机构的官方微博,是越来越多了。当然,这样的官方微博,有的开通之后,就音信杳然,有的则半死不活,也有的相当活跃。广东中山市检察院的官方微博,正义中山,就是一个早上向你问早安,晚上跟

转载 单价合同、总价合同和成本补偿合同 总价包干和单价包干

原文地址:单价合同、总价合同和成本补偿合同作者:崔军-国际工程专单价合同、总价合同和成本补偿合同在国际工程项目中,依据不同的标准,建筑工程合同可以被分为不同的合同类型,但为了风险识别的便利,通常以单价合同、总价合同和成本补偿合

声明:《iPhone4分辨率获取和判断 iphone4逻辑分辨率》为网友雨下听风分享!如侵犯到您的合法权益请联系我们删除