{"version":"0.1.0","code":"0000","result":true,"message":"处理成功","errdetail":"","timestamp":1671508810710,"data":{"id":71712825,"title":"2.6.1 纹理管理","slug":"fgckop","format":"lake","bookId":26046811,"body":null,"body_draft":null,"body_html":"
本章节主要介绍纹理管理,AutoSDK中提到的纹理只用于图层服务中要求展示的纹理。
主图模块的纹理管理和卡片服务提供的纹理生成管理服务的关系是并列的,HMI可以二选一。区别是主图模块的纹理输入要求是一张已经合成的图片,而卡片服务内部可以合成文字和图片并进行纹理管理。
注意:若使用卡片服务,卡片服务内自带纹理管理,则不需要HMI额外用到主图的纹理管理。
只有在不使用卡片服务时,图层中涉及的纹理通过主图服务的纹理管理添加删除纹理。
图层纹理需要的是一张已经合成的图片,如图:
com.autonavi.gbl.map.layer.model.LayerTexture
该参数内锚点配置方法和坐标配置方法详见:6.6.1纹理锚点配置方法和6.6.2纹理坐标配置方法
/**\n * @brief 地图Layer纹理的数据参数\n */\nclass LayerTexture {\n /**\n * 资源id\n */\n public int resID;\n /**\n * 数据缓存\n */\n public BinaryStream dataBuff;\n /**\n * 锚点类型 MapOverlayIconAnchor\n */\n public @LayerIconAnchor.LayerIconAnchor1 int anchorType;\n /**\n * 宽度\n */\n public long width;\n /**\n * 高度\n */\n public long height;\n /**\n * x方向比率 ,取值范围[0,1],仅在anchorType为MapOverlayIconAnchorRandomPosition 任意锚点类型时使用\n */\n public float xRatio;\n /**\n * y方向比率 ,取值范围[0,1],仅在anchorType为MapOverlayIconAnchorRandomPosition 任意锚点类型时使用\n */\n public float yRatio;\n /**\n * 纹理\n */\n public @LayerIconType.LayerIconType1 int iconType;\n /**\n * 是否生成mipmap\n */\n public boolean isGenMipmaps;\n /**\n * 是否重复平铺方式\n */\n public boolean isRepeat;\n /**\n * 错误码\n */\n public int errorCode;\n /**\n * 名称,model纹理需要\n */\n public String name;\n /**\n * 纹理是否预乘透明通道,1:预乘;0:未预乘 \n */\n public boolean isPreMulAlpha;\n}
boolean com.autonavi.gbl.map.MapView.addLayerTexture(LayerTexture texture)
boolean com.autonavi.gbl.map.MapView.updateTexture(LayerTexture param)
boolean com.autonavi.gbl.map.MapView.destroyTexture(int resId)
LayerTexture com.autonavi.gbl.map.MapView.getLayerTexture(int resId)
long com.autonavi.gbl.map.MapView.getUsedTextureCount()
long com.autonavi.gbl.map.MapView.getCapacityTextureCount()
说明:函数详情,请复制函数名称到在线API搜索
LayerTexture layerTexture = new LayerTexture();\nlayerTexture.isRepeat = false;\nlayerTexture.anchorType = LayerIconAnchorRandomPosition; \nlayerTexture.xRatio = 0.1;\nlayerTexture.yRatio = 0.2;\nlayerTexture.isGenMipmaps = false;\nlayerTexture.isPreMulAlpha = false;\n\nBitmap bitmap = FileUtils.getResDrawableBitmap(CC.getApplication(), "./res/pic.png");\nif (bitmap == null) {\n return -1;\n}\n\nByteBuffer dataBuffer = ByteBuffer.allocate(bitmap.getByteCount());\nbitmap.copyPixelsToBuffer(dataBuffer);\nlayerTexture.dataBuff = new BinaryStream(dataBuffer.array());\n\nlayerTexture.width = bitmap.getWidth();\nlayerTexture.height = bitmap.getHeight();\nlayerTexture.iconType = LayerIconTypeBMP;\nsynchronized (this) {\n layerTexture.resID = 1000;//每个纹理id需要不同,该处示例\n mMapView.addLayerTexture(layerTexture);\n}
因为AutoSDK有最大纹理缓存个数限制(默认500个),可以通过MapView.getUsedTextureCount()实时获取已用纹理个数,超出后无法添加纹理成功。所以HMI需要在纹理不再使用时及时释放,AutoSDK建议的策略是:
1、对于静态纹理,所谓静态纹理是固定的图片文件,而不是动态合成的。若使用一次后在退出前可能继续使用,可不删除,但该纹理总数也不能超过最大缓存个数。
2、对于动态纹理,所谓动态纹理是动态合成文字和图片的临时单次使用的纹理,在纹理变更或者图层图元销毁时需要及时销毁,避免大量的动态纹理未销毁导致纹理缓存耗尽。
","body_lake":null,"pub_level":null,"status":"0","updated_at":"2022-04-06 07:01:51","deleted_at":null,"nameSpace":"mnlcaa/v610","browseCount":136,"collectCount":0,"estimateDate":7,"docStatus":0,"permissions":true,"overView":false}}