• 解决 UIView 设置背景为UIImage图片变型问题[XXX setBackgroundColor:[UIColor colorWithPatternImage:XXX]];


        [self.drawingViewsetBackgroundColor:[UIColorcolorWithPatternImage:[selfthumbnailWithImageWithoutScale:image size:self.drawingView.frame.size]]];

     

    - (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize

    {

        UIImage *newimage;

        if (nil == image)

        {

            newimage = nil;

        }

        else

        {

            CGSize oldsize = image.size;

            CGRect rect;

            if (asize.width/asize.height > oldsize.width/oldsize.height)

            {

                rect.size.width = asize.height*oldsize.width/oldsize.height;

                rect.size.height = asize.height;

                rect.origin.x = (asize.width - rect.size.width)/2;

                rect.origin.y = 0;

            }

            else

            {

                rect.size.width = asize.width;

                rect.size.height = asize.width*oldsize.height/oldsize.width;

                rect.origin.x = 0;

                rect.origin.y = (asize.height - rect.size.height)/2;

            }

            UIGraphicsBeginImageContext(asize);

            CGContextRef context = UIGraphicsGetCurrentContext();

            CGContextSetFillColorWithColor(context, [[UIColorclearColor] CGColor]);

            UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background

            [image drawInRect:rect];

            newimage = UIGraphicsGetImageFromCurrentImageContext();

            UIGraphicsEndImageContext();

        }

        return newimage;

    }

  • 相关阅读:
    浮动float 摆放位置
    边框(border)宽度样式颜色 和基本属性
    调用css文件,进行调色
    deque_01
    iterator_教程中的讲解
    vector_01
    VS2013_CodeLens
    Qt for Embedded Linux
    jsjl_for_ubuntu12.04
    VC6_导入lib库
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/3456155.html
Copyright © 2020-2023  润新知