iOS图像处理之绘制直线

-(void)drawLine:(CGPoint)fromPnt toPoint:(CGPoint)toPnt{

float xScale = theImageView.image.size.width/theImageView.frame.size.width;

float yScale = theImageView.image.size.height/theImageView.frame.size.height;

UIGraphicsBeginImageContext(theImageView.image.size);

[theImageView.image drawInRect:CGRectMake(0, 0, theImageView.image.size.width, theImageView.image.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0*[self returnMax:xScale withNumber:yScale]);

CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);

CGContextBeginPath(UIGraphicsGetCurrentContext());

CGContextMoveToPoint(UIGraphicsGetCurrentContext(), fromPnt.x*xScale, fromPnt.y*yScale);

CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), toPnt.x*xScale, toPnt.y*yScale);

CGContextStrokePath(UIGraphicsGetCurrentContext());

theImageView.image=UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

时间: 2024-08-30 09:34:15

iOS图像处理之绘制直线的相关文章

详解OS X和iOS图像处理框架Core Image

转自:http://www.csdn.net/article/2015-02-13/2823961-core-image 摘要:本 文结合实例详解了OS X和iOS图像处理框架Core Image的使用,如何通过Core Image来创建和使用iOS的内置滤镜,非常适合初学者学习.虽然示例代码是用Swift写的iOS程序,不过实现概念很容易转换到 Objective-C和OS X. 这篇文章会为初学者介绍一下Core Image,一个OS X和iOS的图像处理框架. 如果你想跟着本文中的代码学习

IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字

概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat)y1 toX:(CGFloat)x2 toY:(CGFloat)y2 context:(CGContextRef)con{ CGContextMoveToPoint(con, x1, y1); CGContextAddLineToPoint(con, x2, y2); CGContextSetLi

封装 用canvas绘制直线的函数--面向对象

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>用面向对象的思想 封装 在canvas绘制直线的函数</title> 6 </head> 7 <body> 8 <canvas id="cv"></canvas> 9 &

iOS 图像处理-剪裁图像

解决问题:按照某一长宽比例,剪裁图片的上部和下部,保留中间的内容.当然也可以自定义需要剪裁留下的区域 前提:需要添加Framework:CoreGraphics.framework 代码: - (UIImage*) crop:(UIImage*)theImage{ // Get size of current image CGSize size = [theImage size]; // Create rectangle that represents a cropped image CGFlo

iOS 图像处理 - 图像拼接

解决问题:将两个图像拼接在一起 前提:需要添加Framework:CoreGraphics.framework 源码: - (UIImage *) combine:(UIImage*)leftImage :(UIImage*)rightImage { CGFloat width = leftImage.size.width * 2; CGFloat height = leftImage.size.height; CGSize offScreenSize = CGSizeMake(width, h

iOS 图像处理 - 模糊图像

解决问题:将图像模糊 前提:添加 CoreGraphics.framework 源码: - (UIImage*) blur:(UIImage*)theImage { // create our blurred image CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage]; // setting up G

2. Quartz2D 绘制直线

#import <UIKit/UIKit.h> @interface MyView : UIView @end #import "MyView.h" @implementation MyView -(void) drawRect:(CGRect)rect{ [self drawLine]; } #pragma mark - 绘图方法 #pragma mark 绘制直线 -(void) drawLine{ //提示:使用Ref声明的对象,不需要用* //1. 获取上下文 -

iOS界面的绘制和渲染

界面的绘制和渲染 UIView是如何到显示的屏幕上的. 这件事要从RunLoop开始,RunLoop是一个60fps的回调,也就是说每16.7ms绘制一次屏幕,也就是我们需要在这个时间内完成view的缓冲区创建,view内容的绘制这些是CPU的工作:然后把缓冲区交给GPU渲染,这里包括了多个View的拼接(Compositing),纹理的渲染(Texture)等等,最后Display到屏幕上.但是如果你在16.7ms内做的事情太多,导致CPU,GPU无法在指定时间内完成指定的工作,那么就会出现卡

多媒体编程——ios视频图像绘制工具类。

IOS上视频级的图像绘制 ios上的图像绘制常规的是 UIView的drawRect函数,但是这个函数是异步触发,并且由主线程执行.虽然可以通过一定技巧达到主动绘制的效果: 1.传递图像给UIView缓存着. 2.然后调用UIView的setNeedDisplay 改写重绘标志. (以上两步是讲图像丢给UIView,让它自己进行绘制,但是绘制的时机不可控,有时候我们需要它马上绘制,甚至有时候我们需要知道它什么时候绘制完成了,就需要下面两步) 3.在播放线程中调用UIView的 perfromOn