create a new image with only masked part (without transparent area) with new size

不羁岁月 提交于 2019-12-25 05:16:18

问题


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.

Thanks


回答1:


You can:

  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


来源:https://stackoverflow.com/questions/8834732/create-a-new-image-with-only-masked-part-without-transparent-area-with-new-siz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!