iOS设置截图背景图片透明
/**
设置图片背景为透明
*/
- (UIImage *)imageToTransparent {
// 分配内存
const int imageWidth = self.size.width;
const int imageHeight = self.size.height;
size_t bytesPerRow = imageWidth * 4;
uint32_t *rgbImageBuf = (uint32_t *)malloc(bytesPerRow * imageHeight);
// 创建conxt
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImageBuf, imageWidth, imageHeight, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeight), self.CGImage);
// 遍历像素
int pixelNum = imageWidth * imageHeight;
uint32_t *pCurPtr = rgbImageBuf;
for (int i = 0; i < pixelNum; i++, pCurPtr++) {
if ((*pCurPtr & 0xFFFFFF00) == 0xffffff00) {
uint8_t *ptr = (uint8_t *)pCurPtr;
ptr[0] = 0;
}
}
// 将内存转成image
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rgbImageBuf, bytesPerRow * imageHeight, ProviderReleaseData);
CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, 8, 32, bytesPerRow, colorSpace, kCGImageAlphaLast | kCGBitmapByteOrder32Little, dataProvider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
UIImage *resultImage = [UIImage imageWithCGImage:imageRef];
// 释放
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return resultImage;
}
iOS设置截图背景图片透明的更多相关文章
- ios - UINavigationBar添加背景图片的几种简单思路
UITabBarController下面常常需要为多个ViewController设置导航栏样式,总结了一下遇到过的为UINavigationBar添加背景图片的几种简单思路 以设置背景图片为例: 第 ...
- android设置背景图片透明
设置Activiyt为透明可以在Activity中引用系统透明主题android:theme="@android:style/Theme.Translucent" 设置背景图片透明 ...
- IOS 在IOS6中设置navigationBar背景图片 会有一条 黑色阴影 --- 解决方案
//给navigationBar设置背景图片 if ([self.navigationController.navigationBar respondsToSelector:@selector(set ...
- css 设置背景图片透明
最终效果: 背景图片css不变,再背景图片的里层元素设置css样式即可 opacity:0.4; filter:alpha(opacity=40); /* 针对 IE8 以及更早的版本 */
- 设置VS2017背景图片
设置方法很简单:安装扩展ClaudiaIDE 1.在这里下载扩展,https://visualstudiogallery.msdn.microsoft.com/9ba50f8d-f30c-4e33-a ...
- iOS 设置导航栏全透明
- (void)viewWillAppear:(BOOL)animated{ //设置导航栏背景图片为一个空的image,这样就透明了 [self.navigationController.navig ...
- 设置JFrame背景图片
这里我就放上改写的代码吧,不做多的解释,推荐一个好的博文 https://blog.csdn.net/jdsjlzx/article/details/16831815 public void ini_ ...
- 设置按钮背景图片(HTML-CSS)
很多人提交表单时都喜欢用一个图片来作为提交按钮,大多数人可能用JS去操作表单的提交,即当用户点击这个图片时响应一个JS来提交表单.其实还有一种方法,就是直接设置SUBMIT按钮的图片背景.设置它的图片 ...
- MFC 设置窗口背景图片
//在Onpaint函数中加入如下代码 //----------给窗口设置背景图片---------------------------- CPaintDC dc(this); CRect myrec ...
随机推荐
- Android第二次作业
另一成员链接:https://www.cnblogs.com/2575590018dqy/p/10053353.html
- CentOS 7 下使用yum安装MySQL5.7.20 最简单图文详解
CentOS7默认数据库是mariadb, 但是 好多用的都是mysql ,但是CentOS7的yum源中默认好像是没有mysql的. 上一篇安装的是5.6的但是我想安装5.7的 yum安装是最简单 ...
- expdp用户10迁移到新环境11之正式实施
expdp迁移源端数据库:cu 源端IP: 源端schema: xxx目标数据库:ora 目标IP:xxx操作流程:31日凌晨应用停,随后使用数据泵迁移,两套库迁移,迁移一套,迁移完毕应用确 ...
- 用matlab画漂亮的sin曲线
Technorati 标记: matlab,plot 相信大部分用过matlab的人都画过sin曲线,直接plot就可以了,不过呢,plot出来的曲线自然不那么好看,本着绳命在于折腾的原则,小弟学习了 ...
- [LeetCode&Python] Problem 671. Second Minimum Node In a Binary Tree
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each no ...
- CSS学习笔记_day1
目录 一. 什么是HTML 二.编辑器 三.Html的基本骨架 四.html基本标签 h.p.img.a.audio.video.ul>li.ol>li.dl dd dt.span.div ...
- 6th week blog(2)
fixed:元素将从常规文档流中删除,并且不会为页面布局中的元素创建任何空间.它的位置相对于初始位置.它允许框架样式布局.在页式媒体如打印输出中,一个固定元素会出现于第一页的相同位置.这可以用来创建一 ...
- slf4j的使用
1.导入jar包 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api< ...
- ideal的maven工程启动时老是报错,提示web.xml里面的监听器找不到,但是实际又是存在的
-X clean compile package -Dmaven.repo.local=D:\repository-pss -Dmaven.test.skip=true maven仓库地址
- a链接中 JS弹出确认对话框方法
一种: <a href="javascript:if(confirm('确实要删除该内容吗?'))location='http://www.google.com'">弹 ...