如何在GMS3.x中从RGB位图创建techniqueIcon



在GMS 3.x中,我们可以使用自定义的技术创建"技术"图标:

Image techniqueIcon := RGBImage( "Test icon", 4, 75, 75 )
techniqueIcon = RGB( icol, irow, iradius )
String techniqueName = "MyTechnique"
Object technique = CreateTechnique( techniqueName, techniqueIcon  )

如何使"techniqueIcon"具有适当的透明度(即alpha通道(?我尝试了RGBA((函数,但结果图标仍然没有我想要的透明度。但是,我可以从外部应用程序创建*.PNG格式的图标,并通过"管理自定义技术…"菜单命令将其分配给一种技术。

我认为目前没有通过脚本设置图标透明度的正确方法。DM脚本并不完全支持RGB图像中的alpha值。




然而,您的评论很有趣,请发送我进行实验。

在标记浏览器中查看时,保存在提供位置的标记似乎不是典型的"数组"标记,因为这些标记将显示为(values not shown)。相反,它显示为一个长字符串。

以字节为单位的标记大小(如TagGroupGetTagSize()所示(与位图的4字节*宽度*高度相匹配。

假设图标中的每个像素都有R、G、B和Alpha的字节大小值,我猜"字符串"只是DigitalMicrograph表示二进制数组数据的方式,因为它不是已知的数组形式(也称为图像(。

这让我想出了以下脚本:

RGBImage GetBitMapFromCustomTechniqueIcon( number index)
{
RGBImage bitmap 
taggroup tg
string path = "WorkflowManager:Custom Techniques:["+index+"]"
if ( !GetPersistentTagGroup().TagGroupGetTagAsTagGroup(path,tg) ) Throw("Tagpath not found")
number w,h
if ( !tg.TagGroupGetTagAsLong("Bitmap height",h) ) Throw("Height tag not found")
if ( !tg.TagGroupGetTagAsLong("Bitmap width",w) ) Throw("Width tag not found")
string str
if ( !tg.TagGroupGetTagAsString("Bitmap data",str) ) Throw("Bitmap data tag not found.")
{
number nPts = w*h
if ( str.len()/4 != nPts ) Throw("Data length does not seem to match icon size")
image imgR := IntegerImage("Red",1,0,w,h)
image imgG := IntegerImage("Green",1,0,w,h)
image imgB := IntegerImage("Blue",1,0,w,h)
image imgA := IntegerImage("Alpha",1,0,w,h)
// Browse and convert string
for( number i=0; i<nPts; i++)
{
imgR[i%w,i/w] = asc(str.mid(i*4,1))
imgG[i%w,i/w] = asc(str.mid(i*4+1,1))
imgB[i%w,i/w] = asc(str.mid(i*4+2,1))
imgA[i%w,i/w] = asc(str.mid(i*4+3,1))
}
imgR.FlipVertical()
imgG.FlipVertical()
imgB.FlipVertical()
imgA.FlipVertical()
bitmap := RGBA(imgR,imgG,imgB,imgA)
}
return bitmap
}

有了这个脚本,我确实能够读取存储的图标,并将其显示为RGB图像。然而,我在写标签时并不那么成功。图标永远不会正确更新,即使在DM重新启动后也是如此。

void WriteCustomTechniqueIcon(number index,image imgR,image imgG,image imgB,image imgA)
{
taggroup tg
string path = "WorkflowManager:Custom Techniques:["+index+"]"
if ( !GetPersistentTagGroup().TagGroupGetTagAsTagGroup(path,tg) ) Throw("Tagpath not found")
number w = imgR.ImageGetDimensionSize(0)
number h = imgR.ImageGetDimensionSize(1)
if ( w != imgG.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgG.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
if ( w != imgB.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgB.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
if ( w != imgA.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgA.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
tg.TagGroupSetTagAsLong("Bitmap height",h)
tg.TagGroupSetTagAsLong("Bitmap width",w) 
imgR.FlipVertical()
imgG.FlipVertical()
imgB.FlipVertical()
imgA.FlipVertical()
// Create encoded data string
string str = ""
number nPts=w*h
for( number i=0; i<nPts; i++)
{
str+= uncchr(sum(imgR[i%w,i/w]))
str+= uncchr(sum(imgG[i%w,i/w]))
str+= uncchr(sum(imgB[i%w,i/w]))
str+= uncchr(sum(imgA[i%w,i/w]))
}
tg.TagGroupSetTagAsString("Bitmap data",str) 
}

不知道我错过了什么。



编辑

当我欺骗系统并使用下面的代码写一个4倍图像大小的uint8数组时,我几乎得到了

void WriteCustomTechniqueIcon2(number index,image imgR,image imgG,image imgB,image imgA)
{
taggroup tg
string path = "WorkflowManager:Custom Techniques:["+index+"]"
if ( !GetPersistentTagGroup().TagGroupGetTagAsTagGroup(path,tg) ) Throw("Tagpath not found")
number w = imgR.ImageGetDimensionSize(0)
number h = imgR.ImageGetDimensionSize(1)
if ( w != imgG.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgG.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
if ( w != imgB.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgB.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
if ( w != imgA.ImageGetDimensionSize(0) ) Throw( "Images not of same size" )
if ( h != imgA.ImageGetDimensionSize(1) ) Throw( "Images not of same size" )
tg.TagGroupSetTagAsLong("Bitmap height",h)
tg.TagGroupSetTagAsLong("Bitmap width",w) 
imgR.FlipVertical()
imgG.FlipVertical()
imgB.FlipVertical()
imgA.FlipVertical()
image array := IntegerImage("",1,0,w*4,h)
array.slice2(0,0,0, 0,w,4,1,h,1) = imgB
array.slice2(1,0,0, 0,w,4,1,h,1) = imgG
array.slice2(2,0,0, 0,w,4,1,h,1) = imgR
array.slice2(3,0,0, 0,w,4,1,h,1) = imgA
tg.TagGroupSetTagAsArray("Bitmap data",array)
}

DM重新启动后,图标加载。然而,颜色都变暗了,我真的不知道为什么。然而,Alpha正在工作(包括混合值(

最新更新