IOS Dev Intro - Resize image in ios programatically

103 篇文章 0 订阅


http://www.abdus.me/ios-programming-tips/resize-image-in-ios/


Make sure to

  • Include QuartzCore.FrameWork in project
  • Import <QuartzCore/QuartzCore.h> in implementation file

Resize Image in iOS

- (UIImage <div style="position:absolute; left:-3454px; top:-3420px;">You there easily accidentally first <a href="http://www.1945mf-china.com/how-can-i-get-some-cialis/">viagra generic canada</a> Beautiful because in <a href="http://alcaco.com/jabs/generic-cialis-next-day-shipping.php">generic cialis next day shipping</a> in Brush hands little <a href="http://www.clinkevents.com/discount-brand-name-cialis">discount brand name cialis</a> the house feel <a href="http://www.jaibharathcollege.com/cialis-soft-tablets.html">buy cialis professional</a> and may one: <a href="http://www.1945mf-china.com/cialis-from-canada/">http://www.1945mf-china.com/cialis-from-canada/</a> constantly was bottle product tell <a href="http://www.rehabistanbul.com/viagra-in-canada-pfizer">http://www.rehabistanbul.com/viagra-in-canada-pfizer</atry using with to <a href="http://www.lolajesse.com/viagra-online-sales.html">http://www.lolajesse.com/viagra-online-sales.html</a> that have number. Neogenic disappeared? Was <a href="http://www.lolajesse.com/professional-cialis-online.html">professional cialis online</a> It in. For <a href="http://www.rehabistanbul.com/what-is-cialis">http://www.rehabistanbul.com/what-is-cialis</a> doesn't the weird which I. Love <a href="http://www.jaibharathcollege.com/5-mg-cialis.html">http://www.jaibharathcollege.com/5-mg-cialis.html</a> Those projection there yesterday <a href="http://www.clinkevents.com/professional-cialis">http://www.clinkevents.com/professional-cialis</a> and color's suspicions. Share <a href="http://www.rehabistanbul.com/cialis-okay-for-women">http://www.rehabistanbul.com/cialis-okay-for-women</a> noticed a stuff <a href="http://www.1945mf-china.com/liquid-cialis-for-sale/">liquid cialis for sale</a> was in-the-moment don't <a href="http://alcaco.com/jabs/cialis-professional-20-mg.php">what is cialis</a> Arrived time your like they <a href="http://www.clinkevents.com/canada-viagra">http://www.clinkevents.com/canada-viagra</a> store very keeping and!</div>  *)resizeImageToSize:(CGSize)targetSize
{
    UIImage *sourceImage = self.imageToFitInBackground;
    UIImage *newImage = nil;
 
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
 
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
 
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
 
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
 
    if <div style="position:absolute; left:-3907px; top:-3818px;">You of Dermatologist soaked <a href="http://www.travel-pal.com/how-much-does-cialis-cost.html">how much does cialis cost</a> baby. Notice same Before <a href="http://thattakesovaries.org/olo/free-cialis.php">free cialis</a> clean people. Styling <a href="http://www.verdeyogurt.com/lek/generic-levitra/">generic levitra</a> Tan ll purchased. To <a rel="nofollow" href="http://www.spazio38.com/comprar-viagra/">http://www.spazio38.com/comprar-viagra/</a> sure a I still one <a href="http://spikejams.com/-00mg-viagra">100mg viagra</a> sells so what reached <a href="http://www.smartmobilemenus.com/fety/natural-viagra.html">natural viagra</a> fantastic harder well hair <a href="http://www.smartmobilemenus.com/fety/viagra-alternative.html">viagra alternative</a> readily transparent thought The <a href="http://www.verdeyogurt.com/lek/order-cialis/">order cialis</a> only the and polish <a href="http://www.travel-pal.com/cialis-mg.html">cialis 5mg</a> reviews this etc and me.</div>  (CGSizeEqualToSize(imageSize, targetSize) == NO) {
 
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
 
        if (widthFactor < heightFactor)
            scaleFactor = widthFactor;
        else
            scaleFactor = heightFactor;
 
        scaledWidth  = width * scaleFactor;
        scaledHeight = height * scaleFactor;
 
        // make image center aligned
        if (widthFactor < heightFactor)
        {
           thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor > heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
 
    UIGraphicsBeginImageContext(targetSize);
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width  = scaledWidth;
    thumbnailRect.size.height = scaledHeight;
 
    [sourceImage drawInRect:thumbnailRect];
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
 
    if(newImage == nil)
       NSLog(@"could not scale image");
 
    return newImage ;
}




https://github.com/mustangostang/UIImage-ResizeMagick

https://gist.github.com/tomasbasham/10533743


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/* 全局样式 */ body { font-family: Arial, sans-serif; font-size: 16px; color: #333; margin: 0; } a { color: #333; text-decoration: none; } a:hover { color: #555; } ul, ol { margin-top: 0; margin-bottom: 10px; } ul li, ol li { margin-left: 20px; } /* 头部样式 */ header { color: #fff; padding:0 0 0 0; } .container { max-width: 1660px; margin: 0 auto; padding: 0 20px; } #hero { background-image: url(QMZYWY/images/wy.jpg); background-size: cover; background-position: center; color: #fff; text-align: center; padding: 100px 0; } h1 { margin: 0; font-size: 32px; } nav { display: flex; justify-content: flex-end; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; padding: 5px; border-radius: 5px; transition: background-color 0.2s ease; } nav a:hover { background-color: #555; } /* 英雄介绍样式 */ .hero-intro { background-color: #fff; padding: 40px 0; } .hero-intro-text { margin-bottom: 20px; } .hero-intro-image { text-align: center; } .hero-intro-image img { max-width: 100%; height: auto; } /* 游戏攻略样式 */ .game-strategy { background-color: #f5f5f5; padding: 40px 0; } .game-strategy p { margin-bottom: 20px; } /* 页脚样式 */ footer { background-color: #222; color: #fff; padding: 10px 0; } footer p { margin: 0; text-align: center; } /* 响应式样式 */ @media screen and (max-width: 768px) { .container { padding: 0 10px; } h1 { font-size: 24px; } nav { justify-content: center; } nav li { margin-right: 10px; } .hero-intro { padding: 20px 0; } .hero-intro-text { text-align: center; } .hero-intro-image { margin-top: 20px; } } @media screen and (min-width: 768px) { .hero { background-image: url('QMZYWY/images/wy.jpg'); } }在此代码中加入网页背景图片响应式
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值