Open bernard-ingenuity opened 4 years ago
Hi, there.
Currently, you can't add images to annotation labels. As a workaround, you can subclass SCIAnnotationLabel, override onDraw:assetManager:, create a texture from your image and draw it instead of a label. See the code below:
import SciChart.Protected.SCIAnnotationLabel
import UIKit
class ImageLabelAnnotation: SCIAnnotationLabel {
let image: UIImage
init(image: UIImage) {
self.image = image
}
private let textureID = SCIResourceId()
override func onDraw(_ renderContext: ISCIRenderContext2D, assetManager: ISCIAssetManager2D) {
let bitmap = image.sciBitmap()
var texture = SCIAssetManagerUtil.tryGetTexture(with: textureID, size: frame.size, from: assetManager)
if (texture == nil) {
texture = assetManager.texture(with: image.sciBitmap())
assetManager.storeResource(textureID, resource: texture!)
} else {
renderContext.update(texture!, withPixels: bitmap.data)
}
renderContext.drawTexture(texture!, in: self.frame)
}
}
Let us know if it works for you
Hi SciChart team,
I would like to add and image to annotation without any text. Here is my code to create annotation:
` triggerHorizontalLine.set(y1: 0.0)
And also I added an extension:
`import SciChart
extension SCIAnnotationLabel {
}`
And then later I add an image
self.triggerLineList[self.selectedTabIndex].annotationLabels.firstObject.addImage(imageName: ImageNames.btnDutyImage)
App is crashing in the library and here is the debug output:
If I add text to the attributed string crash issue is getting fixed but it does not show my image:
It would be great if you could show me how to add image to annotation labels.
Thanks