Bitmap Images and Image Masks

  Bitmap images and image masks are like any drawing primitive in Quartz. Both images and image masks in Quartz are represented by the CGImageRef data type. Keep in mind that a bitmap image is an array of bits at a specific resolution.

  A bitmap image (or sampled image) is an array of pixels (or samples). Each pixel represents a single point in the image. JPEG, TIFF, and PNG graphics files. With the use of the alpha component, they can appear to take on a variety of shapes and can be rotated and clipped.

  Quartz also supports image masks. An image mask is a bitmap that specifies an area to paint, but not the color. In effect, an image mask acts as a stencil to specify where to place color on the page. Quartz uses the current fill color to paint an image mask. An image mask can have a depth of 1 to 8 bits.

Creating Images

  If you want to create a CGImage object from an image file that uses a standard image format such as PNG or JPEG, the easiest solution is to call the function CGImageSourceCreateWithURL to create an image source and then call the function CGImageSourceCreateImageAtIndex to create an image from the image data at a specific index in the image source. If the original image file contains only one image, then provide 0 as the index. If the image file format supports files that contain multiple images, you need to supply the index to the appropriate image, keeping in mind that the index values start at 0.

  If you’ve drawn content to a bitmap graphics context and want to capture that drawing to a CGImage object, call the function CGBitmapContextCreateImage.

  Several functions are utilities that operate on existing images, either to make a copy, create a thumbnail, or create an image from a portion of a larger one. Regardless of how you create a CGImage object, you use the function CGContextDrawImage to draw the image to a graphics context. Keep in mind that CGImage objects are immutable. When you no longer need a CGImage object, release it by calling the function CGImageRelease.

  Functions for creating images:

  

Creating an Image Mask

  A value of 1 is transparent and 0 is opaque. Image masks are 1, 2, 4, or 8 bits per component. For a 1-bit mask, a sample value of 1 specifies sections of the mask that block the current fill color. A sample value of 0 specifies sections of the mask that show the current fill color of the graphics state when the mask is painted. You can think of a 1-bit mask as black and white; samples either completely block paint or completely allow paint.

Masking an Image with an Image Mask

  The function CGImageCreateWithMask returns the image that’s created by applying an image mask to an image. This function takes two parameters:

  • The image you want to apply the mask to. This image can’t be an image mask or have a masking color (see “Masking an Image with Color”) associated with it.
  • An image mask created by calling the function CGImageMaskCreate. It’s possible to provide an image instead of an image mask, but that gives a much different result. See “Masking an Image with an Image.”

Using Blend Modes with Images

You can use Quartz 2D blend modes (see “Setting Blend Modes”) to composite two images or to composite an image over any content that’s already drawn to the graphic context. This section discusses compositing an image over a background drawing.

The general procedure for compositing an image over a background is as follows:

  1. Draw the background.
  2. Set the blend mode by calling the function CGContextSetBlendMode with one of the blend mode constants. (The blend modes are based upon those defined in the PDF Reference, Fourth Edition, Version 1.5, Adobe Systems, Inc.)
  3. Draw the image you want to composite over the background by calling the function CGContextDrawImage.

Bitmap Images and Image Masks的更多相关文章

  1. Quartz2D 编程指南(三)渐变、透明层 、数据管理

    概览 图形上下文 路径 颜色与颜色空间 变换 图案 阴影 渐变 透明层 Quartz 2D 中的数据管理 位图与图像遮罩 CoreGraphics 绘制 Layer 渐变 简介 渐变是从一个颜色到另外 ...

  2. Quartz2D 编程指南(一)概览、图形上下文、路径、颜色与颜色空间

    概览 图形上下文 路径 颜色与颜色空间 变换 图案 阴影 渐变 透明层 Quartz 2D 中的数据管理 位图与图像遮罩 CoreGraphics 绘制 Layer 0.说明 本篇博客主要是对官方文档 ...

  3. Quartz 2D编程指南(2)图形上下文(Graphics Contexts)

    Graphics Contexts       一个Graphics Context表示一个绘制目标(也能够理解为图形上下文).它包括绘制系统用于完毕绘制指令的绘制參数和设备相关信息.Graphics ...

  4. Bitmap.Config 说明 ALPHA_8 ARGB_4444 ARGB_8888 RGB_565

    这篇文章的目的是了解Bitmap.Config 你可以在使用这个方法的时候会遇到 Bitmap android.graphics.Bitmap.createBitmap(int width, int ...

  5. ANDROID开发之OOM:一张图片(BitMap)占用内存的计算 图片内存优化

    Android中一张图片(BitMap)占用的内存主要和以下几个因数有关:图片长度,图片宽度,单位像素占用的字节数. 一张图片(BitMap)占用的内存=图片长度*图片宽度*单位像素占用的字节数 注: ...

  6. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  7. 【开源毕设】一款精美的家校互动APP分享——爱吖校推 [你关注的,我们才推](持续开源更新3)附高效动态压缩Bitmap

    一.写在前面 爱吖校推如同它的名字一样,是一款校园类信息推送交流平台,这么多的家校互动类软件,你选择了我,这是我的幸运.从第一次在博客园上写博客到现在,我一次一次地提高博文的质量和代码的可读性,都是为 ...

  8. Android Bitmap 和 ByteArray的互相转换

    Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...

  9. Android-Drawable、Bitmap、byte[]、资源文件相互转换

    我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...

随机推荐

  1. java之美妙的注解

    注解 一.认识注解 先看百度百科对java注解的解释: 定义:注解(Annotation),也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它 ...

  2. VMware 11 安装 Mac OS X10.10

    一.下载好以下软件--->http://pan.baidu.com/s/1qWDkTbe 1,VMware 11 2,unlocker203(装好VMware11后需要安装补丁unlocker才 ...

  3. C#在64位操作系统上连接Oracle的问题和解决方案

    C#使用System.Data.OracleClient连接Oracle数据库.之前在WinXP上正常运行的程序移植到Windows 2008 x64上之后就连不上数据库了.错误信息如下: 尝试加载O ...

  4. 解决Mybatis没有代码提示

    MyBatis xml文件中代码自动提示 工具/原料   eclipse,maven 方法/步骤   1 一.获得mybatis-3-config.dtd.mybatis-3-mapper.dtd 这 ...

  5. Windows 10 上的 Git 如何清除密码? Git Credential Manager for Windows

    Windows 10 上的 Git 如何清除密码? 因为一台新的电脑是 Windows 10 在第一次使用 Git 要求输入密码时把密码给输错了. 之前提交都是说 Token 错了,不再出现提示密码. ...

  6. QT win 安装配置

    QT windows 版安装配置 安装包:链接:https://pan.baidu.com/s/1LCj2V3xQ1wB9_7zmE5tV6Q 密码:bn9r 首先安装QT Creator 双击安装文 ...

  7. [转]iis 重新安装后 重新注册asp.net

    iis 重新安装后 重新注册asp.net 服务器IIS问题: 卸载并重新安装了IIS.... 解决方法:原因是IIS重装后要重新安装一下.NET Framework. 开始-->运行--> ...

  8. mysql安装过程及注意事项

    1.1. 下载: 我下载的是64位系统的zip包: 下载地址:https://dev.mysql.com/downloads/mysql/ 下载zip的包: 下载后解压:D:\软件安装包\mysql- ...

  9. SSH 自动化安装部署遇到的问题

    1. 对于需要添加unknown host的问题可以通过添加: -o StrictHostKeyChecking=no 例如: ssh -o StrictHostKeyChecking=no acco ...

  10. Xshell连接虚拟机突然被拒,提示再次输入密码。。。

    sudo vim /etc/ssh/sshd_config 将 # Authentication: LoginGraceTime 120 PermitRootLogin prohibit-passwo ...