用新尺寸仅用遮罩的部分(无透明区域)创建新图像 [英] create a new image with only masked part (without transparent area) with new size

查看:117
本文介绍了用新尺寸仅用遮罩的部分(无透明区域)创建新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遮罩和一个应用了遮罩的图像,以获取该图像的一部分. 问题是当我在图像上应用该蒙版时,从蒙版生成的图像的大小与原始图像的大小相同.尽管未蒙版的部分是透明的.我需要的是仅具有原始图像蒙版部分的图像,我不希望透明部分出现在图像中.这样生成的图像将具有较小的尺寸,并且仅包含蒙版部分.

I have a mask and an image on which mask is applied to get a portion of that image. The problem is when I apply that mask on the image ,the resultant image from masking is of same size as the original image .Though the unmasked part is transparent. What I need is an image which only has the masked part of the original image ,I dont want transparent part to be in the image. so that the resultant image will be of smaller size an contain only the masked part.

谢谢

推荐答案

您可以:

  1. 以实际大小将图像绘制到新的CGBitmapContext,为位图提供缓冲区. CGBitmapContextCreate
  2. 从位图中读取alpha值以确定透明边界.您将必须根据指定的像素数据确定如何读取此内容.
  3. 创建新的CGBitmapContext来提供外部缓冲区,使用以下方式的变体或组合:a)像素偏移量,b)每行偏移量字节,或c)手动移动位图的数据(适当地减少内存使用量,如果可能的话). CGBitmapContextCreate
  4. 从第二个位图上下文创建一个CGImage. CGBitmapContextCreateImage
  1. Draw the image to a new CGBitmapContext at actual size, providing a buffer for the bitmap. CGBitmapContextCreate
  2. Read alpha values from the bitmap to determine the transparent boundaries. You will have to determine how to read this based on the pixel data you have specified.
  3. Create a new CGBitmapContext providing the external buffer, using some variation or combination of: a) a pixel offset, b) offset bytes per row, or c) manually move the bitmap's data (in place to reduce memory usage, if possible). CGBitmapContextCreate
  4. Create a CGImage from the second bitmap context. CGBitmapContextCreateImage

这篇关于用新尺寸仅用遮罩的部分(无透明区域)创建新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆