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.

最新文章

  1. css3 画圆记录
  2. 递归,回溯,DFS,BFS的理解和模板【摘】
  3. Android开发之在子线程中使用Toast
  4. Android常见开发思路
  5. javascript它【蛇系列】第一弹:简单的蛇实现
  6. 初步谈谈 C# 多线程、异步编程与并发服务器
  7. SQL Server2008 安装失败后的解决办法
  8. Laravel日志
  9. Linux stress 命令
  10. windows中用bat脚本更改环境变量
  11. VS从数据库表生成Model代码
  12. poj1988(判断一个结点下面有多少个结点,推荐)
  13. golang学习之接口型函数
  14. 1. MNIST读取数据
  15. HDU1869 六度分离
  16. python高级(三)—— 字典和集合(泛映射类型)
  17. 【lua】如何倒序查找字符
  18. linux命令(6):tar命令
  19. crash处理core文件
  20. (转载)深入super,看Python如何解决钻石继承难题

热门文章

  1. PDO exec 执行时出错后如果修改数据会被还原?
  2. 【linux】centos6.5搭建svn
  3. MySQL建表规范与常见问题 (go)
  4. Nagios配置文件说明
  5. selenium笔记2017
  6. poj 2377 Bad Cowtractors (最大生成树prim)
  7. Oracle11g 搭建单实例DataGuard (转载)
  8. django-csrf_exempt
  9. leetcode232
  10. 利用Nginx rewrite规则实现域名显性转发