1

リモートソースからアプリのアイコンを読み込む必要があります。画像は50x50pxで、デバイスに25x25pxで表示されます。

現在、アイコンは網膜デバイスでは正しいサイズを示していますが、網膜以外のデバイスでは2倍のサイズを示しています。

参考:リモートソースが網膜以外の画像を提供する方法はありません。

網膜以外のデバイスでUIImageを縮小して、すべてのデバイスが同じサイズで表示されるようにするにはどうすればよいですか?

4

3 に答える 3

7

まず、Retinaディスプレイがあるかどうかを確認します

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){

次に、画像のスケールオプションを設定する必要があります。

UIImage * scaledImage = [UIImage alloc];
scaledImage = [[scaledImage initWithCGImage:[resourceImage CGImage] scale:2.0 orientation:UIImageOrientationUp] autorelease];

次に、imageViewはそれをスケーリングして正しく表示する必要があると思います

于 2012-09-10T16:22:15.747 に答える
0

これを試して:

+ (UIImage *) onScaleImage:(UIImage *)image width:(int)width
{
    CGImageRef imageRef = image.CGImage;

    NSUInteger nWidth = CGImageGetWidth(imageRef);
    if (nWidth == width)
        return (nil);

    double dScaleFactor = (double)width / (double)nWidth;

    NSUInteger nHeight = (int)((double)CGImageGetHeight(imageRef) * dScaleFactor);

    CGContextRef context = CGBitmapContextCreate(NULL, width, nHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef), CGImageGetBitmapInfo(imageRef));

    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextSetShouldAntialias(context, true);

    CGContextDrawImage (context, CGRectMake(0, 0, width, nHeight), imageRef);
    CGImageRef imageRefScaled = CGBitmapContextCreateImage(context);

    // caller must retain
    UIImage *imageScaled = [[UIImage alloc] initWithCGImage:imageRefScaled];

    CGContextRelease (context);
    CGImageRelease (imageRefScaled);

    return (imageScaled);
}
于 2012-09-10T16:21:50.880 に答える
0

そうですね、次のように、すべての呼び出しをifステートメントでラップすることができます。

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    //do scale stuff here
}

毎回これを入力しないようにするために、UIScreenでカテゴリを宣言できます。これは、-realScaleメソッドなどの内部でこのコードを使用します。

于 2012-09-10T16:29:10.330 に答える