0

我制作了一个必须打印图像的应用程序。我需要打印具有预定义尺寸的图像。

例如,我有一些 50 x 50 像素的图像,我想将其调整为一些新尺寸的像素,在打印后我得到尺寸为 5 x 5 厘米的图像。

请看附件:

在此处输入图像描述

感谢帮助!

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 回答