1. 从UIView中获取图像相当于窗口截屏。
(ios提供全局的全屏截屏函数UIGetScreenView(). 如果需要特定区域的图像,可以crop一下)
-
CGImageRef screen = UIGetScreenImage();
-
UIImage* image = [UIImage imageWithCGImage:screen];
2. 对于特定UIView的截屏。
(可以把当前View的layer,输出到一个ImageContext中,然后利用这个ImageContext得到UIImage)
-
-(UIImage*)captureView: (UIView *)theView
-
{
-
CGRect rect = theView.frame;
-
UIGraphicsBeginImageContext(rect.size);
-
CGContextRef context =UIGraphicsGetCurrentContext();
-
[theView.layer renderInContext:context];
-
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
-
UIGraphicsEndImageContext();
-
return img;
-
}
3. 如果需要裁剪指定区域。
(可以path & clip,以下例子是建一个200x200的图像上下文,再截取出左上角)
-
UIGraphicsBeginImageContext(CGMakeSize(200,200));
-
CGContextRefcontext=UIGraphicsGetCurrentContext();
-
UIGraphicsPushContext(context);
-
// …把图写到context中,省略[indent]CGContextBeginPath();
-
CGContextAddRect(CGMakeRect(0,0,100,100));
-
CGContextClosePath();[/indent]CGContextDrawPath();
-
CGContextFlush(); // 强制执行上面定义的操作
-
UIImage* image = UIGraphicGetImageFromCurrentImageContext();
-
UIGraphicsPopContext();
4. 存储图像。
(分别存储到home目录文件和图片库文件。)
存储到目录文件是这样
-
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@“Documents”] stringByAppendingPathComponent:@“image.png”];
-
[UIImagePNGRepresentation(image) writeToFile:path atomically:YES];
若要存储到图片库里面
- UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
5. 互相转换UImage和CGImage。
(UImage封装了CGImage, 互相转换很容易)
-
UIImage* imUI=nil;
-
CGImageRef imCG=nil;
-
imUI = [UIImage initWithCGImage:imCG];
-
imCG = imUI.CGImage;
6. 从CGImage上获取图像数据区。
(在apple dev上有QA, 不过好像还不支持ios)
下面给出一个在ios上反色的例子
-
-(id)invertContrast:(UIImage*)img
-
{
-
CGImageRef inImage = img.CGImage;
-
CGContextRef ctx;
-
CFDataRef m_DataRef;
-
m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
-
int width = CGImageGetWidth( inImage );
-
int height = CGImageGetHeight( inImage );
-
int bpc = CGImageGetBitsPerComponent(inImage);
-
int bpp = CGImageGetBitsPerPixel(inImage);
-
int bpl = CGImageGetBytesPerRow(inImage);
-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
-
int length = CFDataGetLength(m_DataRef);
-
NSLog(@“len %d”, length);
-
NSLog(@“width=%d, height=%d”, width, height);
-
NSLog(@“1=%d, 2=%d, 3=%d”, bpc, bpp,bpl);
-
for (int index = 0; index < length; index += 4)
-
{
-
m_PixelBuf[index + 0] = 255 - m_PixelBuf[index + 0];// b
-
m_PixelBuf[index + 1] = 255 - m_PixelBuf[index + 1];// g
-
m_PixelBuf[index + 2] = 255 - m_PixelBuf[index + 2];// r
-
}
-
ctx = CGBitmapContextCreate(m_PixelBuf, width, height, bpb, bpl, CGImageGetColorSpace( inImage ), kCGImageAlphaPremultipliedFirst );
-
CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
-
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
-
CGContextRelease(ctx);
-
return rawImage;
-
}
7. 显示图像数据区。
(显示图像数据区,也就是unsigned char*转为graphics context或者UIImage或和CGImageRef)
- CGContextRef ctx = CGBitmapContextCreate(pixelBuf,width,height, bitsPerComponent,bypesPerLine, colorSpace,kCGImageAlphaPremultipliedLast );
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

总结一下这三次面试下来我的经验是:
-
一定不要死记硬背,要理解原理,否则面试官一深入就会露馅!
-
代码能力一定要注重,尤其是很多原理性的代码(之前两次让我写过Node中间件,Promise.all,双向绑定原理,被虐的怀疑人生)!
-
尽量从面试官的问题中表现自己知识的深度与广度,让面试官发现你的闪光点!
-
多刷面经!
我把所有遇到的面试题都做了一个整理,并且阅读了很多大牛的博客之后写了解析,免费分享给大家,算是一个感恩回馈吧,有需要的朋友【点击我】获取。祝大家早日拿到自己心怡的工作!
篇幅有限,仅展示部分内容
的朋友【点击我】获取。祝大家早日拿到自己心怡的工作!**
篇幅有限,仅展示部分内容