Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android C代码编译不正确_Android_Compilation_Android Ndk - Fatal编程技术网

Android C代码编译不正确

Android C代码编译不正确,android,compilation,android-ndk,Android,Compilation,Android Ndk,我写了一个简单的循环来帮助广告牌检查像素是否为白色。如果是这样,它将设置为100%透明度。我用本机代码编写它,因为这个循环的java等价物运行256x256位图需要19秒,太慢了 在编译时: #include "org_me_renderscene_Billboard.h" #include <stdio.h> #include <stdlib.h> JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboa

我写了一个简单的循环来帮助广告牌检查像素是否为白色。如果是这样,它将设置为100%透明度。我用本机代码编写它,因为这个循环的java等价物运行256x256位图需要19秒,太慢了

在编译时:

#include "org_me_renderscene_Billboard.h"

#include <stdio.h>
#include <stdlib.h>

JNIEXPORT jintArray JNICALL Java_org_me_renderscene_Billboard_NativeSetAlphaWhereWhite
  (JNIEnv *envptr, jclass jClass, jintArray pixels, jint length)
{
    int *mPixels = (*int)malloc(length * 4);

    static int currentcolor;
    static int writecolor;
    static int red, green, blue;

    for(int x = 0; x < length; x++)
    {
        currentcolor = pixels[x];

        red = currentcolor << 16;
        green = currentcolor << 8;
        blue = currentcolor;
        if((red == 0) && (green == 0) && (blue == 0))
        {
            mPixels[x] = 0x00000000;
        }
        else
        {
            mPixels[x] = currentcolor;
        }
    }

    return mPixels;
#包括“org_me_renderscene_Billboard.h”
#包括
#包括
JNIEXPORT jintArray JNICALL Java_Organg_me_renderscene_Billboard_NativeSetalphawhere白色
(JNIEnv*envptr,jclass-jclass,jintArray像素,jint长度)
{
int*mPixels=(*int)malloc(长度*4);
静态颜色;
静态int-writecolor;
静态int红色、绿色、蓝色;
对于(int x=0;x(int*)
而不是
(*int)
尝试
(int*)
而不是
(*int)

应该是

int *mPixels = (int*)malloc(length * 4);
int *mPixels = (int*)malloc(length * 4);
甚至更好

int *mPixels = (int*)malloc(length * sizeof(int));
还请注意,这不会正确区分红色、绿色和蓝色:

red = currentcolor << 16;
green = currentcolor << 8;
blue = currentcolor;
这将使像素的Alpha值为零,只留下RGB部分。如果整个值为零,则每种颜色都必须为零,因此无需单独检查每种颜色

最后的想法:

我对Android没有做太多的具体操作,但是0x000000黑色和0xFFFFFF白色不是吗?所以你实际上是在匹配黑色而不是白色

应该是

int *mPixels = (int*)malloc(length * 4);
int *mPixels = (int*)malloc(length * 4);
甚至更好

int *mPixels = (int*)malloc(length * sizeof(int));
还请注意,这不会正确区分红色、绿色和蓝色:

red = currentcolor << 16;
green = currentcolor << 8;
blue = currentcolor;
这将使像素的Alpha值为零,只留下RGB部分。如果整个值为零,则每种颜色都必须为零,因此无需单独检查每种颜色

最后的想法:


我对Android没有做太多具体的工作,但0x000000黑色和0xFFFFFF白色不是吗?所以你实际上是在这里匹配黑色而不是白色。

你在Android.mk中使用了什么标志

您是否设置了本地标签:=-std=c99

你需要换成这个


你在Android.mk中使用了什么标志

您是否设置了本地标签:=-std=c99

你需要换成这个