• 关于

    cgcontextref

    的搜索结果

问题

iOS里像CGContextRef这样以Ref结尾的是基于什么原理

发现iOS里有很多类似CGContextRef这样的定义,查看api文档发现是定义为指向一个结构的指针typedef struct CGContext * CGContextRef;不知道这样的用法是出于什么样的考虑才这么用的。是单纯了为了...
a123456678 2019-12-01 20:27:52 1330 浏览量 回答数 1

问题

CGContextRef 画不出直线

为什么我用下面的代码就画不出直线呢,屏幕一片空白- (void)viewDidLoad { [super viewDidLoad]; CGContextRef context = UIGraphicsGetCurrentCo...
a123456678 2019-12-01 20:27:45 836 浏览量 回答数 1

回答

void CGContextClearRect ( CGContextRef c, CGRect rect );
a123456678 2019-12-02 03:15:13 0 浏览量 回答数 0

回答

确保有context:CGContextRef context = UIGraphicsGetCurrentContext();然后aColor = [UIColor blackColor]; [aColor setStroke]; CGContextSetLineWidth(context, 2.0f); CGContextAddPath(context, pathRef); CGContextStrokePath(context);
爵霸 2019-12-02 02:22:20 0 浏览量 回答数 0

回答

继承UIView,重写方法- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(context, 20, 20); CGContextAddLineToPoint(context, 100,100); CGContextStrokePath(context); }
a123456678 2019-12-02 03:12:58 0 浏览量 回答数 0

回答

问题描述不明确。 如果在UIView中绘制矩形,在-(void)drawRect 中来画。-(void)drawRect { CGRect rect=self.bounds; CGContextRef context=UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context,[UIColor redColor].CGColor); CGContextSetFillRect (context, rect); }
爵霸 2019-12-02 02:14:16 0 浏览量 回答数 0

回答

重载UIView子类中的drawRect:方法,自己在drawRect:里面画倒影 CGContextRef context = UIGraphicsGetCurrentContext(); UIFont *myFont = [UIFont systemFontOfSize:17]; CGContextSetShadow(context, CGSizeMake(5, 5), 2); [@"需要倒影的文字" drawAtPoint:CGPointMake(50, 50) withFont:myFont];
a123456678 2019-12-02 03:12:55 0 浏览量 回答数 0

回答

如果你只是要修改全部层次:layer.backgroundColor = [[UIColor greenColor] CGColor];如果要充填的形状比较复杂,需要重写层次的drawInContext- (void)drawInContext:(CGContextRef)context { //... CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]); CGContextFillPath(context); //... }
爵霸 2019-12-02 02:18:38 0 浏览量 回答数 0

回答

只要能知道各个点的位置及控制点.绘制弧度应该能够画出来. void CGContextAddArc ( CGContextRef c, CGFloat x, //圆心的x坐标 CGFloat y, //圆心的x坐标 CGFloat radius, //圆的半径 CGFloat startAngle, //开始弧度 CGFloat endAngle, //结束弧度 int clockwise //0表示顺时针,1表示逆时针 );
爵霸 2019-12-02 02:17:06 0 浏览量 回答数 0

问题

给drawRect矩形区域着色

大家好,应用中有一个drawRect,我想给指定的矩形区域上颜色,怎么实现?目前我用的方法:- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsG...
爵霸 2019-12-01 19:28:33 736 浏览量 回答数 1

问题

CGContext画图功能,调整图片尺寸大小后图片失真

我使用CGContext在UIImageView中画手绘线。下面的代码:UIGraphicsBeginImageContext(self.frame.size);CGContextRef context= UIGraphicsGetCurr...
爵霸 2019-12-01 19:32:15 1236 浏览量 回答数 1

问题

关于iphone使用drawRect画圆

我要在UIView中画一个简单的圆形。我不想用QuartzCore,能不能用drawRect实现?- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCur...
爵霸 2019-12-01 19:24:01 825 浏览量 回答数 1

问题

关于在UITableViewcell中划线的问题

drawRect代码如下:-(void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef cxt = UIGraphicsGetCurrentContex...
爵霸 2019-12-01 19:22:25 744 浏览量 回答数 1

问题

关于iphone中的圆形相框效果

想用下面的代码实现一个圆形相框:CGContextRef context = CGBitmapContextCreate(NULL, self.bounds.size.width, self.bounds.size.height, 8, 4...
爵霸 2019-12-01 19:24:02 773 浏览量 回答数 1

问题

设置iphone中的UIToolbar的颜色

在ios4.3以上版本,想把UIToolbar的颜色改成灰色,但是下面的代码没有实现:- (void)drawRect:(CGRect)rect { UIGraphicsBeginImageContext(rect.size); ...
爵霸 2019-12-01 19:32:07 818 浏览量 回答数 1

回答

方法不止一种,可以用category,可以直接骗用户,可以...这里说一种继承,步骤如下:1)继承UITextfield2)重写子类中的- (void)drawRect:(CGRect)rect 如下(void)drawRect:(CGRect)rect {CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame), 0.5));}3)TestCode 如下:import "CustomField.h"@implementation ViewController(void)viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CustomField *textField = [CustomField new]; textField.frame = CGRectMake(0, 200, 100, 30); textField.backgroundColor = [UIColor yellowColor]; [self.view addSubview:textField];}
a123456678 2019-12-02 03:15:27 0 浏览量 回答数 0

问题

用UIImage读取灰度图像素数据为0

上面是我要读取的灰度图,单通道8位。我用了UIImage和CGImage来读取这张图的像素数据: UIImage *heightmap = [UIImage imageNamed:[_terrainFiles valueForKey:HEI...
a123456678 2019-12-01 20:27:52 1076 浏览量 回答数 1

问题

剪裁图片导致图片向左旋转

做了一个剪裁图片的程序,调用剪裁:`UIImage* croppedImage = [self imageCrop:imageView toRect:CGRectMake(10.0, 50.0, 320, 100)];`方法:{ /...
爵霸 2019-12-01 19:22:30 768 浏览量 回答数 1

问题

初学iPhone上用Quartz 2D画图? 400 报错

初学iPhone上用Quartz 2D画图? 400 报错 参考了An iOS 4 iPhone Graphics Drawing Tutorial using Quartz 2D这篇文章,用了30分钟在iPhone上画出了...
爱吃鱼的程序员 2020-06-03 15:06:07 1 浏览量 回答数 1

回答

你的代码修改成这样就可以了 - (IBAction)minus:(id)sender { self.radius = @([self.radius floatValue]+10.0f); [self redrawImage]; } - (IBAction)plus:(id)sender { self.radius = @([self.radius floatValue]-10.0f); [self redrawImage]; } -(void)redrawImage { //set the original image first [_imageView setImage:[UIImage imageNamed:@"your image goes here"]]; CGFloat size = [self.radius floatValue]; CGContextRef context = CGBitmapContextCreate(NULL, self.view.bounds.size.width, self.view.bounds.size.height, 8, 4 * self.view.bounds.size.width, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst); CGContextAddArc(context, 320/2, 460/2, size, 0, 2*M_PI, 0); CGContextClosePath(context); CGContextClip(context); CGContextDrawImage(context, self.view.bounds, _imageView.image.CGImage); CGImageRef imageMasked = CGBitmapContextCreateImage(context); CGContextRelease(context); UIImage *newImage = [UIImage imageWithCGImage:imageMasked]; CGImageRelease(imageMasked); [_imageView setImage:newImage]; UIGraphicsEndImageContext(); }
爵霸 2019-12-02 02:18:49 0 浏览量 回答数 0

问题

如何使用Alpha蒙版剪切和填充画布

我有一些.alpha蒙版的.png图标。我需要使用Android SDK将它们渲染为可绘制的图像。 在iPhone上,我使用以下命令获取此结果,使用黑色作为填充,将“图像” alpha蒙版转换为“...
LiuWH 2020-01-24 17:18:32 1 浏览量 回答数 1

问题

如何使用Alpha蒙版剪切和填充画布

我有一些.alpha蒙版的.png图标。我需要使用Android SDK将它们渲染为可绘制的图像。 在iPhone上,我使用以下命令获取此结果,使用黑色作为填充,将“图像” alpha蒙版转换为“...
LiuWH 2020-01-25 11:31:29 0 浏览量 回答数 1

问题

关于iPhone,不知道为啥视图变成黑色的

视图变成了一个黑色的矩形,下面是画视图的代码: - (void)drawRect:(CGRect)rect { //// General Declarations CGContextRef context = UIGraph...
爵霸 2019-12-01 20:26:13 730 浏览量 回答数 1

回答

(UIImage *)fixOrientation:(UIImage *)aImage { // No-op if the orientation is already correct if (aImage.imageOrientation == UIImageOrientationUp) return aImage; // We need to calculate the proper transformation to make the image upright. // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. CGAffineTransform transform = CGAffineTransformIdentity; switch (aImage.imageOrientation) { case UIImageOrientationDown: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height); transform = CGAffineTransformRotate(transform, M_PI); break; case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: transform = CGAffineTransformTranslate(transform, aImage.size.width, 0); transform = CGAffineTransformRotate(transform, M_PI_2); break; case UIImageOrientationRight: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, 0, aImage.size.height); transform = CGAffineTransformRotate(transform, -M_PI_2); break; default: break; } switch (aImage.imageOrientation) { case UIImageOrientationUpMirrored: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, aImage.size.width, 0); transform = CGAffineTransformScale(transform, -1, 1); break; case UIImageOrientationLeftMirrored: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, aImage.size.height, 0); transform = CGAffineTransformScale(transform, -1, 1); break; default: break; } // Now we draw the underlying CGImage into a new context, applying the transform // calculated above. CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height, CGImageGetBitsPerComponent(aImage.CGImage), 0, CGImageGetColorSpace(aImage.CGImage), CGImageGetBitmapInfo(aImage.CGImage)); CGContextConcatCTM(ctx, transform); switch (aImage.imageOrientation) { case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: case UIImageOrientationRight: case UIImageOrientationRightMirrored: // Grr... CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage); break; default: CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage); break; } // And now we just create a new UIImage from the drawing context CGImageRef cgimg = CGBitmapContextCreateImage(ctx); UIImage *img = [UIImage imageWithCGImage:cgimg]; CGContextRelease(ctx); CGImageRelease(cgimg); return img; }
a123456678 2019-12-02 03:14:14 0 浏览量 回答数 0

问题

iOS UIView 为什么绘制的三角形区域未能填充颜色渐变

// YSHHypnosisView.m // Hypnosister #import "YSHHypnosisView.h" @implementation YSHHypnosisView // Only override ...
a123456678 2019-12-01 19:22:24 1030 浏览量 回答数 1

回答

http://www.cnblogs.com/hanhongmin/p/3498102.html我们在PickerDelegate中能够拿到UIImage拿到后转变成cocos2dx可用的格式,回调HelloWord的方法再干一些事,比如显示出来。 关于把方法当参数传进来之类的我一概不懂,所以在PickerDelegate中直接调HelloWorld,所以.m改成.mm以实现混编。 我们先说UIImage的数据转换 复制代码 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { //CCLog("selected"); //处理数据 UIImage* image = [info valueForKey:UIImagePickerControllerOriginalImage]; CGImageRef imageRef = [image CGImage]; NSUInteger width = CGImageGetWidth(imageRef); NSUInteger height = CGImageGetHeight(imageRef); CCLog("%i,%i",width,height); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char* rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char)); NSUInteger bytesPerPixel = 4; NSUInteger bytesPerRow = bytesPerPixel * width; NSUInteger bitsPerComponent = 8; CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); CGContextRelease(context); cocos2d::CCTexture2D *pickedImage = new cocos2d::CCTexture2D(); pickedImage->initWithData(rawData, cocos2d::kCCTexture2DPixelFormat_RGBA8888, width, height, cocos2d::CCSizeMake(width, height)); CCLOG("%f,%f",pickedImage->getContentSize().width,pickedImage->getContentSize().height); [picker dismissModalViewControllerAnimated: YES]; [picker release]; } 复制代码 以上,我们已经把图片数据转换到了CCTexture2D,至于为何这么转,我也是搜来哒~注意引入响应头文件,这个以后就不说了。 HelloWorld声明和定义接口,接收CCTexture2D并干一些我们想干的事。 .h void pickedPhoto(CCTexture2D* texture); .cpp void HelloWorld::pickedPhoto(CCTexture2D* texture){ CCSprite* sprite = CCSprite::createWithTexture(texture); this->addChild(sprite); } CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); layer->setTag(1); scene->addChild(layer); return scene; } UIImage+fixOrientation.h文件 复制代码 1 // 2 // UIImage+fixOrientation.h 3 // OpenCamera 4 // 5 // Created by HanHongmin on 13-12-30. 6 // 7 // 8 9 #import 10 11 @interface UIImage (fixOrientation)12 -(UIImage*) fixOrientation;13 @end复制代码UIImage+fixOrientation.m文件 复制代码 1 // 2 // UIImage+fixOrientation.m 3 // OpenCamera 4 // 5 // Created by HanHongmin on 13-12-30. 6 // 7 // 8 9 #import "UIImage+fixOrientation.h"10 11 @implementation UIImage (fixOrientation)12 - (UIImage *)fixOrientation {13 if (self.imageOrientation == UIImageOrientationUp) return self;14 15 UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);16 [self drawInRect:(CGRect){0, 0, self.size}];17 UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();18 UIGraphicsEndImageContext();19 return normalizedImage;20 }21 @end复制代码以上有啥不明白的,自己搜去吧我也说不明白。这个东西用了之后,据说手机内存会突然增大大概40-50M,求良药啊 在PickerDelegate中引用上面的头文件,得到UIImage后调一下。 UIImage* image = [info valueForKey:UIImagePickerControllerOriginalImage]; image = [image fixOrientation]; 试试~~ 图片拾取后发现只显示了一部分, 自行处理一下吧。我在项目中用的时候,sprite是早就创建好的,大小是整个屏幕,只是获得Texture的时候更换到了sprite中,没啥问题的。
杨冬芳 2019-12-02 03:02:08 0 浏览量 回答数 0

回答

Re如何让IOS中的文本实现3D效果 提供一个方法,不断的重复画文本的layer,创建有层次的效果: 创建UIImage Category,命名为UIImage+3d.h文件: ////  UIImage+3D.h////  Created by Lefteris Haritou on 12/10/12.//  Feel Free to use this code, but please keep the credits//#import <UIKit/UIKit.h>@interface UIImage (Extensions)+ (UIImage *)create3DImageWithText:(NSString *)_text Font:(UIFont*)_font ForegroundColor:(UIColor*)_foregroundColor ShadowColor:(UIColor*)_shadowColor outlineColor:(UIColor*)_outlineColor depth:(int)_depth;@end .m文件: ////  UIImage+3D.m////  Created by Lefteris Haritou on 12/10/12.//  Feel Free to use this code, but please keep the credits//#import "UIImage+3D.h"@implementation UIImage (Extensions)+ (UIImage *)create3DImageWithText:(NSString *)_text Font:(UIFont*)_font ForegroundColor:(UIColor*)_foregroundColor ShadowColor:(UIColor*)_shadowColor outlineColor:(UIColor*)_outlineColor depth:(int)_depth {    //calculate the size we will need for our text    CGSize expectedSize = [_text sizeWithFont:_font constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];    //increase our size, as we will draw in 3d, so we need extra space for 3d depth + shadow with blur    expectedSize.height+=_depth+5;    expectedSize.width+=_depth+5;    UIColor *_newColor;    UIGraphicsBeginImageContextWithOptions(expectedSize, NO, [[UIScreen mainScreen] scale]);    CGContextRef context = UIGraphicsGetCurrentContext();    //because we want to do a 3d depth effect, we are going to slightly decrease the color as we move back    //so here we are going to create a color array that we will use with required depth levels    NSMutableArray *_colorsArray = [[NSMutableArray alloc] initWithCapacity:_depth];    CGFloat *components =  (CGFloat *)CGColorGetComponents(_foregroundColor.CGColor);    //add as a first color in our array the original color    [_colorsArray insertObject:_foregroundColor atIndex:0];    //create a gradient of our color (darkening in the depth)    int _colorStepSize = floor(100/_depth);    for (int i=0; i<_depth; i++) {        for (int k=0; k<3; k++) {            if (components[k]>(_colorStepSize/255.f)) {                components[k]-=(_colorStepSize/255.f);            }        }                _newColor = [UIColor colorWithRed:components[0] green:components[1] blue:components[2] alpha:CGColorGetAlpha(_foregroundColor.CGColor)];        //we are inserting always at first index as we want this array of colors to be reversed (darkest color being the last)        [_colorsArray insertObject:_newColor atIndex:0];    }    //we will draw repeated copies of our text, with the outline color and foreground color, starting from the deepest    for (int i=0; i<_depth; i++) {        //change color        _newColor = (UIColor*)[_colorsArray objectAtIndex:i];        //draw the text        CGContextSaveGState(context);        CGContextSetShouldAntialias(context, YES);                //draw outline if this is the last layer (front one)        if (i+1==_depth) {            CGContextSetLineWidth(context, 1);            CGContextSetLineJoin(context, kCGLineJoinRound);            CGContextSetTextDrawingMode(context, kCGTextStroke);            [_outlineColor set];            [_text drawAtPoint:CGPointMake(i, i) withFont:_font];        }        //draw filling                [_newColor set];        CGContextSetTextDrawingMode(context, kCGTextFill);        //if this is the last layer (first one we draw), add the drop shadow too and the outline        if (i==0) {            CGContextSetShadowWithColor(context, CGSizeMake(-2, -2), 4.0f, _shadowColor.CGColor);        }        else if (i+1!=_depth){            //add glow like blur            CGContextSetShadowWithColor(context, CGSizeMake(-1, -1), 3.0f, _newColor.CGColor);        }        [_text drawAtPoint:CGPointMake(i, i) withFont:_font];        CGContextRestoreGState(context);            }    UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return finalImage;}@end 导入category扩展然后如下使用: UIImage *my3dImage = [UIImage create3DImageWithText:@"3" Font:[UIFont systemFontOfSize:250] ForegroundColor:[UIColor colorWithRed:(200/255.f) green:(200/255.f) blue:(200/255.f) alpha:1.0] ShadowColor:[UIColor blackColor] outlineColor:[UIColor colorWithRed:(225/255.f) green:(225/255.f) blue:(225/255.f) alpha:1.0] depth:8];UIImageView *imgView = [[UIImageView alloc] initWithImage:my3dImage];[self.view addSubview: imgView]; 图片效果:
深白色 2019-12-01 23:20:13 0 浏览量 回答数 0

云产品推荐

上海奇点人才服务相关的云产品 小程序定制 上海微企信息技术相关的云产品 国内短信套餐包 ECS云服务器安全配置相关的云产品 开发者问答 阿里云建站 自然场景识别相关的云产品 万网 小程序开发制作 视频内容分析 视频集锦 代理记账服务 阿里云AIoT