0

画像を印刷するアプリを作りました。事前定義されたサイズで画像を印刷する必要があります。

たとえば、50 x 50 px の画像があり、印刷後にサイズ 5 x 5 cm の画像を取得する新しいサイズのピクセルにサイズ変更したいと考えています。

添付ファイルをご覧ください:

ここに画像の説明を入力

手伝ってくれてありがとう!

4

1 に答える 1

1

アプリで画像のサイズを変更するために以下のコードを使用しました

必要に応じてサイズを設定します

  UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:@"pic"]]]];
        // Resize, crop the image to make sure it is square and renders
        // well on Retina display
        float ratio;
        float delta;
        float px = 100; // Double the pixels of the UIImageView (to render on Retina)
        CGPoint offset;
        CGSize size = image.size;
        if (size.width > size.height) {
            ratio = px / size.width;
            delta = (ratio*size.width - ratio*size.height);
            offset = CGPointMake(delta/2, 0);
        } else {
            ratio = px / size.height;
            delta = (ratio*size.height - ratio*size.width);
            offset = CGPointMake(0, delta/2);
        }
        CGRect clipRect = CGRectMake(-offset.x, -offset.y,
                                     (ratio * size.width) + delta,
                                     (ratio * size.height) + delta);
        UIGraphicsBeginImageContext(CGSizeMake(px, px));
        UIRectClip(clipRect);
        [image drawInRect:clipRect];
        UIImage *imgThumb = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();
        [img setImage:imgThumb];
于 2012-06-13T12:56:05.903 に答える