1.绘图总结:
绘图前设置:
CGContextSetRGBFillColor/CGContextSetFillColorWithColor //填充色
CGContextSetRGBStrokeColor/CGContextSetStrokeColorWithColor //笔颜色
CGContextSetLineWidth //线宽度
绘图后设置:
注: 画完图后,必须
先用CGContextStrokePath来描线,即形状
后用CGContextFillPath来填充形状内的颜色.
2.常见图形绘制:
CGContextFillRect/CGContextFillRects
CGContextFillEllipseInRect
CGContextAddRect/CGContextAddRects
CGContextAddEllipseInRect
CGContextAddLines
CGContextMoveToPoint
CGContextAddLineToPoint
3.常见控制方法:
CGContextSaveGState
CGContextRestoreGState
4.创建内存图像context:
CGBitmapContextCreate <-----CGContextRlease释放
CGColorSpaceCreateWithName (KCGColorSpaceGenericRGB)
CGColorSpaceRlease
CGBitmapContextCreateImage() <-----CGImageRlease 释放.
eg:
CGContextRefMyCreateBitmapContext(intpixelsWide,intpixelsHigh)
{
CGContextRef context=NULL;
CGColorSpaceRefcolorSpace;
void* bitmapData;
int bitmapByteCount;
int bitmapBytesPerRow;
bitmapBytesPerRow =(pixelsWide*4);
bitmapByteCount =(bitmapBytesPerRow*pixelsHigh);
colorSpace=CGColorSpaceCreateDeviceRGB();
bitmapData=malloc(bitmapByteCount);
if(bitmapData==NULL)
{
fprintf(stderr,"Memorynotallocated!");
returnNULL;
}
context=CGBitmapContextCreate(bitmapData, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
if(context==NULL)
{
free(bitmapData);
fprintf(stderr,"Contextnotcreated!");
returnNULL;
}
CGColorSpaceRelease(colorSpace);
returncontext;
}
5.图形的变换:
CGContextTranslateCTM
CGContextRotateCTM
CGContextScaleCTM
6.常用函数:
CGRectContainsPoint();
CGRectContainsRect();
CGRectIntersectsRect();
CGRectIntersection();
CGPointEqualToPoint();
CGSizeEqualToSize();
7.从原图片中取小图.
CGImageCreateWithImageInRect
8.屏幕快照:
#import "QuartzCore/QuartzCore.h"
UIGraphicsBeginImageContext(yourView.frame.size);
[[yourView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage*screenshot =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
from:http://www.cppblog.com/zhangyuntaoshe/articles/123066.html
合并两张bit图到一张image的方法
To graphically merge two images into a new image, you do something like this:
UIImage *result = nil;
unsignedchar *data = calloc(1,size.width*size.height*kBytesPerPixel);
if (data != NULL) {
// kCGImageAlphaPremultipliedLast 为预记录的#define value
// 设置context上下文
CGContextRef context = CGBitmapContextCreate(
data, size.width, size.height, 8, size.width*kBytesPerPixel,
CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
if (context != NULL) {
UIGraphicsPushContext(context);
// Image 为下载的背景图片,用于比较context
CGContextTranslateCTM(context, 0, size.height);
CGContextScaleCTM(context, 1, -1);
[image drawInRect:imageRect];
[image2 drawInRect:image2Rect];
UIGraphicsPopContext();
CGImageRef imageRef = CGBitmapContextCreateImage(context);
if (imageRef != NULL) {
result = [UIImageimageWithCGImage:imageRef];
CGImageRelease(imageRef);
}
CGContextRelease(context);
}
free(data);
}
return result;
关键方法: CGContextRef context = CGBitmapContextCreate();
CGContextTranslateCTM();
CGContextScaleCTM();
CGImageRef imageRef = CGBitmapContextCreateImage(context);
CGImageRelease(imageRef);
分享到:
相关推荐
matlab绘图总结(个人总结).pdfmatlab绘图总结(个人总结).pdf
Simulink仿真绘图总结,很好的学习利用matlab/simulink进行系统仿真的教程
spss统计绘图总结PPT学习教案.pptx
matlab绘图总结,这篇将介绍一些论文绘图中经常碰到的问题,如在一个数量很大的曲线上做标记,平滑一个数据量很少的曲线,绘制面积图,以及如何改进绘图的美感。...
总结了关于matlab下画图的经验和语法
CDC双缓冲防闪屏绘图总结,很全面 如里需要绘多张图,并且有重叠的部份,当鼠标改变窗口大小时,重叠部份有严重的闪烁。非常难看
Matlab绘图总结(二维,三维显示等)
包含以下内容源代码,及最新版的publish功能示例。...2D绘图plot 设置标题,xy轴标签及网格 改变图形窗口背景 绘制多个曲线在一个图上 改变线形及标记 坐标轴(axis)控制 图例 legend 双坐标轴图形绘制 - plotyy
。。。
。。。
MATLAB中的三维绘图函数总结.pdfMATLAB中的三维绘图函数总结.pdfMATLAB中的三维绘图函数总结.pdfMATLAB中的三维绘图函数总结.pdfMATLAB中的三维绘图函数总结.pdf
机械制图经典总结.pptx
作者总结了一些使用arcgis过程中的制图技巧。
MFC 交互式 绘图 打开保存 课程实验
1 二维图像 1.1 二维曲线 plot(x, y, ls="-", lw=1.5, label=None) x, y:横坐标和纵坐标 ls:颜色、点标记、线型列表,如 ls='r*-' 表示红色实线、*形点\uff0cls='g.' 表示绿色散点 lw:线宽度 ...
个人综合了一些vb画图的一些程序,供初学者参考。包括圆,椭圆。矩形,平行西变形,五角形,三角形。等等
C#GDI绘图源码总结,绝对经典,欢迎下载!
总结 让我们开始吧! 1. 项目概述 在本项目中,我们将创建一个简单的Java绘图应用程序,允许用户执行以下操作: 绘制基本形状:用户可以选择绘制线条、矩形和椭圆等基本形状。 选择颜色:用户可以选择绘制的颜色...
# Matplotlib绘图使用总结 本notebook主要分为两部分, - 第一部分将绘图中经常用的属性做了汇总,包括轴刻度标题的添加、中文字体的显示等等。 - 第二部分将经常使用的图做了总结,包括散点图,折线图,柱形图,...
[工作总结]机械制图实习总结.doc