渐变图像和缩放

1.一个倒影小程序,图像处理不是很理解,记一下用到的:

//获取一个渐变图像
-(CGImageRef)createGradientImage:(int)pixlswide Height:(int)pixlshigh{
    CGImageRef cgimage = NULL;
    CGColorSpaceRef space = CGColorSpaceCreateDeviceGray();
    CGContextRef gradientBitmapContext = CGBitmapContextCreate(NULL, pixlswide, pixlshigh, 8, 0, space, 0);

    //定义开始和结束的灰色值
    CGFloat colors[] = {0,1,1,1};
    CGGradientRef grayScaleGradient = CGGradientCreateWithColorComponents(space, colors, NULL, 2);
    CGColorSpaceRelease(space);

    //创建梯度向量的开始和结束点
    CGPoint gradientStartPoint = CGPointZero ;
    CGPoint gradientEntPoint = CGPointMake(0, pixlshigh);

    //绘制渐变为灰度的位图上下文
    CGContextDrawLinearGradient(gradientBitmapContext, grayScaleGradient, gradientStartPoint, gradientEntPoint, kCGGradientDrawsAfterEndLocation);
    CGGradientRelease(grayScaleGradient);
    cgimage = CGBitmapContextCreateImage(gradientBitmapContext);
    CGContextRelease(gradientBitmapContext);
    return cgimage ; 
}

以上为创建渐变图像,CGColorSpaceRef -> CGContextRef = CGBitmapContextCreate 创建位图上下文 -> CGGradientRef 渐变引用(做什么的?)->CGContextDrawLineearGradient 绘制渐变为灰度的位图上下文
xxxRef类型都要释放 :CGcontextRelease

//创建并获取一个位图上下文
-(CGContextRef)MyCreateBitmapContext:(int) pixelswide Height:(int)pixlshigh{
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();//创建色彩空间
    CGContextRef bitmapContext = CGBitmapContextCreate(NULL, pixelswide, pixlshigh, 8, 0, space, kCGBitmapByteOrder32Little);

    CGColorSpaceRelease(space);
    return bitmapContext;
}

2.缩放移动
缩放用CGAffineTransform CGAffineTransformMakeScale
移动用CGAffineTransform CGAffineTransformMakeTranslation

  1. pickerview
    需要实现代理和数据源方法
    -(UIView )pickerView:(UIPickerView )pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    每列显示什么,但是测试时 显示图片有问题

4.viewDidAppear viewDidLoad
前者是图显示后调用,加载xib会调用一次,但是在视图加子视图 addSubview 不会自动调用,需要我们显示调用
另外push视图 也不会调用viewDidAppear ,对UIProGress进行自定义可以在这里加方法

viewDidLoad loadView 下次总结区别。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值