TagGroupGetTagType returns wrong type

依然范特西╮ 提交于 2020-05-15 21:22:31

问题


Basically this is the specific question for my older question which I just can't solve.

I was given an example image for my development. This image contains a (I guess representative) TagGrop that displays the information about how the image is created.

My problem is, that TagGroupGetTagType() of the elements of this TagGroup returns 3 for elements that are TagGroups itself. But TagGroups have the type 0 (confirmed by myself and @BmyGuest in the linked question). The following image shows the output of my example script together with the tag editor dialog. As one can see that every element has the type 3, including TagGroups like Acquision or others.

The image above has been created with the following script:

clearResults();

image img;
img.GetFrontImage();
TagGroup tg = img.ImageGetTagGroup();

TagGroupOpenBrowserWindow(tg, 0);

for(number i = 0; i < tg.TagGroupCountTags(); i++){
    String label = tg.TagGroupGetTagLabel(i);
    number type = tg.TagGroupGetTagType(i, 0);

    result("Index " + label + " has type " + type + "\n");
}

What am I doing wrong? Why does this not work? Is there any way to get the correct type?

This may be related to the file so I created an example file which is missing some of the indices (for protecting the privacy of the people who gave me this file). The posted output is in fact created with this file. So the same problem occurres. This file can be downloaded from https://www.file-upload.net/download-14020685/example.dm4.html.

(For anyone who doesn't like to download files from random pages you can get the base64 encoded file contents here: https://cutpaste.online/notes.html?id=xcix7x9e9sHxMFwF3e5h)


回答1:


A confirmation & Workaround

Using your script and provided file, I can exactly reproduce the result.

Moreover, if I run the following script (in GMS 3.4):

image img := RealImage("Test",4,10,10)
taggroup newTG = NewTagGroup()
newTG.TagGroupSetTagAsString("Test","oh")
img.imagegettaggroup().TagGroupSetTagAsTagGroup("TG",newTG)
img.ShowImage()

And then run your script, I get:

Index GMS Version has type 0
Index TG has type 0

However, if I save the file and then open it up again and run your script, I suddenly get:

Index GMS Version has type 3
Index TG has type 3

So, something has clearly changed and is off. I tried some older data (all saved with GMS 3.x) and I always get a type 3 for TagGroups. I could not find data saved by GMS 2.x or GMS 1.x but would assume either or both would return type 0.

I've also noticed that the command TagGroupGetTagTypeLength returns 0 before saving, but 1 for the loaded image, and I think that might be related.

But there is a workaround you can use, which might solver your actual question. For TagGroups (and TagLists) you can replace your check for the type by an actual attempt to get the tag as a TagGroup, as in:

clearResults();

image img;
img.GetFrontImage();
TagGroup tg = img.ImageGetTagGroup();

TagGroupOpenBrowserWindow(tg, 0);

for(number i = 0; i < tg.TagGroupCountTags(); i++){
    String label = tg.TagGroupGetTagLabel(i);
    number typeL = tg.TagGroupGetTagTypeLength(i);
    number type = tg.TagGroupGetTagType(i, 0);

    result("Index " + label + " has " + typeL + " types. Type = " + type + "\n");
    TagGroup tgtest
    if ( tg.TagGroupGetIndexedTagAsTagGroup(i,tgtest) )
        Result("\tIt is as TagGroup (or TagList)!\n")
}


来源:https://stackoverflow.com/questions/61387398/taggroupgettagtype-returns-wrong-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!