简体   繁体   English

使用iOS混合模式的Android图像和颜色混合

[英]Android image and color blending using iOS blend modes

I am currently porting an application from iOS into Android and I have ran into some difficulties when it comes to image processing. 我目前正在将应用程序从iOS移植到Android中,在图像处理方面遇到了一些困难。

I have a filter class that is comprised of ImageOverlays and ColorOverlays which are applied in a specific order to a given base Bitmap. 我有一个由ImageOverlays和ColorOverlays组成的过滤器类,它们按特定顺序应用于给定的基本Bitmap。 Each ColorOverlays has an RGB color value, a BlendModeId, and an alpha value. 每个ColorOverlay都有一个RGB颜色值,一个BlendModeId和一个alpha值。 Each ImageOverlay has an image Bitmap, a BlendModeId, and an alpha/intensity value. 每个ImageOverlay都有一个图像Bitmap,一个BlendModeId和一个alpha / intensity值。

My main problem is that I need to support the following blend modes taken from iOS: 我的主要问题是我需要支持从iOS获取的以下混合模式:

  1. CGBlendModeNormal CGBlendModeNormal
  2. CGBlendModeMultiply CGBlendModeMultiply
  3. CGBlendModeScreen CGBlendModeScreen
  4. CGBlendModeOverlay CGBlendModeOverlay
  5. CGBlendModeDarken CGBlendModeDarken
  6. CGBlendModeLighten CGBlendModeLighten
  7. CGBlendModeColorDodge CGBlendModeColorDodge

Some of these have corresponding PorterDuff.Mode types in Android while others do not. 其中一些在Android中具有相应的PorterDuff.Mode类型,而其他类型则没有。 What's worse, some of the modes that do exist were introduced in recent versions of Android and I need to run on API level 8. 更糟糕的是,在最近的Android版本中引入了一些确实存在的模式,我需要在API级别8上运行。

Trying to build the modes from scratch is extremely inefficient. 尝试从头开始构建模式效率极低。

Additionally, even with the modes that do exist in API8, I was unable to find methods that blend 2 images but that allow you to specify the intensity of the mask (the alpha value from ImageOverlay). 此外,即使使用API​​8中存在的模式,我也无法找到混合2个图像但允许您指定蒙版强度的方法(来自ImageOverlay的alpha值)。 Similarly with ColorOverlays. 与ColorOverlays类似。

The iOS functions I am trying to replicate in Android are 我试图在Android中复制的iOS功能是

CGContextSetBlendMode(...)
CGContextSetFillColorWithColor(...)
CGContextFillRect(...) - This one is easy
CGContextSetAlpha(...)

I have started looking at small third party libraries that support these blend modes and alpha operations. 我已经开始考虑支持这些混合模式和alpha操作的小型第三方库。 The most promising one was poelocesar's lib-magick which is supposedly a port of ImageMagick . 最有希望的是poelocesar的lib-magick ,它应该是ImageMagick的一个端口。

While lib-magick did offer most of the desired blend modes (called CompositeOperator ) I was unable to find a way to set intensity values or to do a color fill with a blend mode. 虽然lib-magick确实提供了大多数所需的混合模式(称为CompositeOperator ),但我无法找到设置强度值或使用混合模式进行颜色填充的方法。

I'm sure somebody has had this problem before. 我确定之前有人遇到过这个问题。 Any help would be appreciated. 任何帮助,将不胜感激。 BTW, Project specifications forbid me from going into OpenGLES. BTW,项目规范禁止我进入OpenGLES。

It turned out that implementing it in the jni wasn't nearly as painful as previously expected. 事实证明,在jni中实施它并不像以前预期的那样痛苦。 The following link had all the details. 以下链接包含所有详细信息。

How does photoshop blend two images together? photoshop如何将两个图像混合在一起?

Even though I helped you via e-mail, I thought I'd post to your question too in case someone wanted some more explanation :-) 即使我通过电子邮件帮助过你,我想我也会发布你的问题以防万一有人想要更多的解释:-)

2.2 is API level 8, which supports the "libjnigraphics" library in the NDK, which gives you access to the pixel buffer for bitmap objects. 2.2是API级别8,它支持NDK中的“libjnigraphics”库,它允许您访问位图对象的像素缓冲区。 You can do these blends manually - they are pretty simple math calculations and can be done really quickly. 你可以手动完成这些混合 - 它们是非常简单的数学计算,可以很快完成。

Check out this site for Android JNI bitmap information. 查看此站点以获取Android JNI位图信息。

It's really simple, just create a JNI method blend() with any parameters you need (either the color values or possibly another bitmap object to blend together), lock the pixel buffer for that bitmap, do the calculation needed, and unlock the bitmap. 它非常简单,只需使用您需要的任何参数(颜色值或可能要混合在一起的另一个位图对象)创建JNI方法blend(),锁定该位图的像素缓冲区,进行所需的计算并解锁位图。 Link 链接

Care needs to be taken on the format of the bitmap in memory, though, as the shifting/calculation for 565 will be different than 8888. Keep that in mind if it doesn't look exactly correct! 但是,需要注意内存中位图的格式,因为565的移位/计算将不同于8888.如果看起来不完全正确,请记住这一点!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM