在从 wikiitude sdk for Android 成功识别图像后,我想在目标图像顶部显示一张图像。
默认情况下它显示StrokedRectangle. 我在文档中找不到任何关于显示图像的明确想法。所以一些建议将不胜感激。
在从 wikiitude sdk for Android 成功识别图像后,我想在目标图像顶部显示一张图像。
默认情况下它显示StrokedRectangle. 我在文档中找不到任何关于显示图像的明确想法。所以一些建议将不胜感激。
Wikiitude Native SDK 只渲染相机和试用水印。StrokedRectangle 是示例应用程序的一部分。
您将不得不使用 OpenGL 来绘制图像。也许本教程会对您有所帮助。
public static int loadTexture(final Context context, final int resourceId)
{
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false; // No pre-scaling
// Read in the resource
final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
// Bind to the texture in OpenGL
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
// Set filtering
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
// Recycle the bitmap, since its data has been loaded into OpenGL.
bitmap.recycle();
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
return textureHandle[0];
}
这是 Wikitude 示例应用程序中的顶点着色器,用于显示如何放置纹理:
attribute vec4 v_position;
uniform mat4 Projection; // from ImageTarget
uniform mat4 ModelView; // from ImageTarget
uniform mat4 Scale; // create scale matrix based on ImageTarget.getTargetScale
void main()
{
gl_Position = Projection * ModelView * Scale * v_position;
};
如果您对 OpenGL 不满意,可以尝试 Wikiitude JS SDK 或 Unity 插件。