我是Vuforia SDK的新手。我有一个作为目标的图像。我想将此图像放在Imagemarker上。实时Imagemarker的大小各不相同。有没有什么方法可以获得Imagemarker的宽度和高度,以便目标图像完全适合Imagemarker?
答案 0 :(得分:1)
由于您未指定使用Unity
还是本机API,我将假设您使用的是Unity
。
这是您使用Vuforia
API进行操作的方法,将其放在附加到ImageTarget
GameObject的脚本中。
IEnumerator Start()
{
Vuforia.ImageTarget img = GetComponent<Vuforia.ImageTargetBehaviour>().ImageTarget;
// This is rounded of in the console display,
// so individual components are printed afterwards
Debug.Log(img.GetSize());
Debug.Log(img.GetSize().x);
Debug.Log(img.GetSize().y);
Debug.Log(img.GetSize().z);
}
或者,您可以直接使用渲染器的Bounds
。
void Start()
{
Renderer r = GetComponent<Renderer>();
Debug.Log(r.bounds.size.x);
Debug.Log(r.bounds.size.y);
Debug.Log(r.bounds.size.z);
}
毋庸置疑,这只是一个快速解决方案,具体取决于您可能希望在运行时使用此动态创建内容的情况。
答案 1 :(得分:0)
是的,你可以。 将图像标记上的图像放置到您想要的相对大小时,当您运行它时,您将看到图像的大小将与您放置它的标记相对。