我正在使用以下代码从位图中获取像素数据,然后通过 JNI 将数组传递给 cocos2dx。当我在 cocos2d-x 中渲染图像时,红色和蓝色通道是相反的。有没有办法从像素的 int 值分别访问红色、蓝色通道,然后相互交换它们?
JAVA代码
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
int len = bitmap.getWidth() * bitmap.getHeight();
onFacebookImageNative(pixels, len, bitmap.getWidth(), bitmap.getHeight(), bitsPerComponent);
JNI 代码
JNIEXPORT void JNICALL Java_com_xxxx_yyyyo_yyyyo_onFacebookImageNative(JNIEnv* env, jobject,
jintArray pixels, jint dataLen, jint width, jint height, jint bitsPerComponent)
{
yyyyo *yyyyo = yyyyo::singleton();
jint *jArr = env->GetIntArrayElements(pixels, NULL);
int pixelsInt[dataLen];
for (int i=0; i<dataLen; i++){
pixelsInt[i] = (int)jArr[i];
}
yyyyo->onFacebookImage(pixelsInt, (int) dataLen,
CCImage::kFmtRawData, (int) width, (int) height, (int) bitsPerComponent);
}