gpt4 book ai didi

ios以预定义尺寸打印

转载 作者:行者123 更新时间:2023-11-29 04:36:25 27 4
gpt4 key购买 nike

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

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

请参阅附件:

enter image description here

感谢您的帮助!

最佳答案

嘿,我使用下面的代码来调整我的应用程序中的图像大小

根据需要设置尺寸

  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];

关于ios以预定义尺寸打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014992/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com