当前位置: 首页 > news >正文

Android JNI Bitmap指定颜色值替换

#include <jni.h>
#include <string>
#include <android/bitmap.h>
#include <cmath>
#include <android/log.h>
//定义TAG之后,我们可以在LogCat通过TAG过滤出NDK打印的日志
#define TAG "BitmapOperationNative"
// 定义info信息
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,TAG,__VA_ARGS__)void operationBitmap(JNIEnv *env, jobject bitmap, int srcColor, int dstColor) {int result;// 获取源Bitmap相关信息:宽、高等AndroidBitmapInfo sourceInfo;result = AndroidBitmap_getInfo(env, bitmap, &sourceInfo);if (result < 0) {LOGI(" AndroidBitmap_getInfo result=%d ", result);return;}LOGI(" AndroidBitmapInfo format=%d srcColor=%x dstColor=%x", sourceInfo.format, srcColor,dstColor);// 获取源Bitmap像素数据 这里用的是32位的int类型 argb每个8位uint32_t *sourceData;//锁定像素的地址(不锁定的话地址可能会发生改变)result = AndroidBitmap_lockPixels(env, bitmap, (void **) &sourceData);if (result < 0) {LOGI(" AndroidBitmap_lockPixels result=%d ", result);return;}// 遍历各个像素点int color;int red, green, blue, alpha;int width = sourceInfo.width;int height = sourceInfo.height;int w, h;for (h = 0; h < height; h++) {for (w = 0; w < width; w++) {color = sourceData[h * width + w];if (color == srcColor) {sourceData[h * width + w] = dstColor;}}}AndroidBitmap_unlockPixels(env, bitmap);
}extern "C"
JNIEXPORT void JNICALL
Java_com_istep_bitmap_BitmapOperationNative_convertTo(JNIEnv *env, jclass clazz, jobject bitmap,jint src, jint dst) {operationBitmap(env, bitmap, src, dst);
}
http://www.lryc.cn/news/146734.html

相关文章:

  • 测试理论与方法----测试流程的第四个步骤:执行测试,提出缺陷
  • Stable Diffusion 提示词入门指南
  • 基于鹰栖息算法优化的BP神经网络(预测应用) - 附代码
  • 想要搞懂接口测试和功能测试有什么区别,那就必须知道他们的基本原理
  • Spring: HiddenHttpMethodFilter的用法
  • Vue入门学习(一)
  • 软考:中级软件设计师:无线网,网络接入技术,ipv6
  • dart 学习 之 同步生成器(sync*)和 异步生成器(async*)
  • JSX基础
  • Linux Day11---mbash项目(二)
  • 回归预测 | MATLAB实现IBES-ELM改进的秃鹰搜索优化算法优化极限学习机多输入单输出回归预测(多指标,多图)
  • 【Golang】go条件编译
  • 学习创建第一个 React 项目
  • 使用Python构建网络爬虫:提取网页内容和图片资源
  • 推荐两款开源的绘制流程图软件
  • echarts画一个简单的饼图 中间是空的 环有两种颜色一种是底色 一种是百分比的颜色
  • 5 群起集群
  • 前端传参对象套对象的格式,后端进行解析并存入数据库
  • WordPress 网站使用 CDN 后获取访客真实 IP
  • mysql my.ini、登录、用户相关操作、密码管理、权限管理、权限表,角色管理
  • UUID和数据库主键
  • uniapp:蓝牙模块
  • 探索链表:数据结构的精妙之处
  • Java监听mysql的binlog 报错解决办法
  • Javascript 中的 debugger 拦截
  • 深入Golang之Mutex
  • 高并发内存池项目(C++实战项目)
  • G. The Morning Star - 思维
  • 应急物资管理系统|智物资DW-S300提升应急响应能力
  • AI人员打架识别算法