阿里云手机应用开发,调用JNI接口,调用memcpy()函数出错。
JNI接口的实现中,有一段代码,功能是从一副图片中截取中间一部分,具体实现是这样的:
unsigned char *fun(unsigned char *data, int width, int height, int leftTopX, int leftTopY, int nWidth, int nheight)
//data, 图片内存首地址,width, height, 图片宽和高;
//leftTopX, leftTopY,截取区域左上角的点坐标
//nWidth, nHeight, 截取区域的宽和高
{
unsigned char *temp, *tempN;
unsigned char *pxl;
int size = nWidth * nHeight;
pxl = NULL;
if ((pxl = (unsigned char *)malloc(size * sizeof(unsigned char))) == NULL)
{
return NULL;
}
memset(readImg->pxl, 0x00, sizeof(size * sizeof(unsigned char)));
temp = data + width * leftTopY + leftTopX;
tempN = pxl;
for (i = 0; i < nHeight; i++)
{
__android_log_print(ANDROID_LOG_INFO, "[hello-jni.c]", "i is %d", i);
memcpy(tempN, temp, nWidth);
__android_log_write(ANDROID_LOG_INFO, "[hello-jni.c]", "123456789_0");
temp += width;
__android_log_write(ANDROID_LOG_INFO, "[hello-jni.c]", "123456789_1");
tempN += nWidth;
__android_log_write(ANDROID_LOG_INFO, "[hello-jni.c]", "123456789_2");
}
return pxl;
}
上面是这部分完整的代码,这个应用在大部分android手机上都没有问题,但在阿里云手机上就会出错。出现的问题是这样的,
假设nHeight是200,那要循环200次,可是从log上看,每次出错都是循环没有运行完,而且是memcpy这一句出错。
请大侠帮忙看看,问题怎么解决?