Android NDK-如何创建多个只给定大小(宽度和高度)的位图
Android NDK - how to create multiple bitmaps given only size (width and height)
我是这方面的新手——提问、android开发和NDK。我希望我足够清楚。
我需要能够创建多个曲面/位图。例如
Surface s = new Surface (width, height)
- 他们可以相互复制s->复制(s2)将曲面s复制到s2(包括RGBA和alpha文本曲面之间的格式转换以及调整大小/缩放)
- 使用fill(x,u,w,h,color)-用颜色填充矩形(类似glClear)
据我所知,你只有一个ANativeWindow,它是由android_app->window变量提供给你的,如果我使用EGL,我可以创建多达1个EGLSurface。我需要能够创建许多曲面(例如大约100个)。这怎么可能?然后将它们全部闪电式传输到窗口帧缓冲区
还有安卓/位图。h但我不知道如何使用它。但它没有为我提供API来创建表面,只是为了已经创建或类似的东西?
您可以通过JNI调用创建位图:
// setup bitmap class
jclass bitmap_class = (jclass)env->FindClass ("android/graphics/Bitmap");
// setup create method
jmethodID bitmap_create_method = env->GetStaticMethodID (bitmap_class, "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
// get_enum_value return jobject corresponding in our case to Bitmap.Config.ARGB_8888. (the implentation is irrelevant here)
jobject bitmap_config_ARGB = get_enum_value ("android/graphics/Bitmap$Config", "ARGB_8888");
// Do not forget to call DeleteLocalRef where appropriate
// create the bitmap by calling the CreateBitmap method
// Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
jobject bitmap = env->CallStaticObjectMethod (bitmap_class, bitmap_create_method, width, height, bconfig);
// at the end of course clean-up must be done
env->DeleteLocalRef (bitmap);
您可以通过android/bitmap.h
中的API访问一些位图属性和原始像素
AndroidBitmap_getInfo
提供有关格式(仅限ARGB_8888
或alpha)、尺寸、步幅或音高的信息。
CCD_ 4给出了原始像素。完成像素操作后,必须调用AndroidBitmap_unlockPixels
制作fill (color, dimension)
JNI可以提供帮助。这可以通过JNI调用来编写(我将使用java,因为它对我来说更容易编写,读起来更清晰)。
canvas.save ();
canvas.setBitmap (bitmap);
canvas.clipRect (left, top, right, bottom, Region.Op.REPLACE);
canvas.drawColor (color, PorterDuff.Mode.SRC);
canvas.restore ();
将一个位图复制到另一个位图上-copy (src_bitmap, src_rect, dest_rect)
canvas.save ();
canvas.setBitmap (dest_bitmap);
canvas.clipRect (left, top, right, bottom, Region.Op.REPLACE);
canvas.drawBitmap (src_bitmap, src_rect, dest_rect, null);
canvas.restore ();
您可以创建位图并使用jnigraphics库(android/bitmap.h),也可以使用多个EGL纹理。
使用位图,您必须自己实现fill
,因为位图只有基于像素的getter和setter(请参见setPixels(..)
)
相关文章:
- C / C++ 移位/偏移/向左或向右移动位图?
- 如何在快板的屏幕中显示子位图的绘制?
- CreateDIBSection为同一图像返回不一致的位图位值
- C++ 位图中的 ttc 字体
- 使用 GDI+ 旋转位图,然后转换为 HDC
- 难以从 CImageList 设置菜单项位图
- 如何将位图拉伸到父面板(wxWidgets 自定义)
- 如何使用 freetype2 访问单色位图中的像素状态
- 将位图 (bmp) 转换为具有透明度的 png (Windows c++)
- 安卓工作室 |CPP 文件错误错误: 位图库中对"AndroidBitmap_unlockPixels"的未定义引用
- 位图到垫子/2D 数组
- Gdiplus位图没有Alpha通道
- 如何从路径字符串加载Gdiplus::位图
- 在C++中使用Gdiplus创建透明位图
- 用C++压缩内存中的位图
- C++gdi::内存中的位图到PNG图像
- LoadImage 函数不适用于 ImageMagick 创建的位图图像
- (位图)LoadImage() 返回 NULL,GetLastError() 返回 0
- Android NDK-如何创建多个只给定大小(宽度和高度)的位图
- 柏林噪声和高度图/位图