创建一个仅包含新尺寸的遮罩部分(没有透明区域)的新图像

发布于 2024-12-26 06:30:50 字数 161 浏览 3 评论 0原文

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

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2025-01-02 06:30:50

您可以:

  1. 以实际大小将图像绘制到新的 CGBitmapContext 中,为位图提供缓冲区。 CGBitmapContextCreate
  2. 从位图中读取 alpha 值以确定透明边界。您必须根据指定的像素数据确定如何读取它。
  3. 创建一个新的 CGBitmapContext 提供外部缓冲区,使用以下各项的变体或组合:a) 像素偏移,b) 每行偏移字节,或 c) 手动移动位图数据(到位以减少内存)用法,如果可能的话)。 CGBitmapContextCreate
  4. 从第二个位图上下文创建一个 CGImageCGBitmapContextCreateImage

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文