0
我製作了一個必須打印圖像的應用程序。我需要用預定義的大小打印圖像。ios使用預定義大小打印
例如,我有一些圖像50 x 50像素我想調整它大小到一些新的大小的像素,打印後我得到的圖像大小5×5釐米。
請參閱附件:
感謝您的幫助!
我製作了一個必須打印圖像的應用程序。我需要用預定義的大小打印圖像。ios使用預定義大小打印
例如,我有一些圖像50 x 50像素我想調整它大小到一些新的大小的像素,打印後我得到的圖像大小5×5釐米。
請參閱附件:
感謝您的幫助!
嘿,我已經使用下面的代碼,根據我的應用程序
設置大小調整圖像大小,你想
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];