Earlier today, a colleague came to me asking for a way to include an image in a block to be used as mask image. I though it might be interesting to share my response here.
Here is the question I received:
I want to mask a block and display an image on the mask. The image is stored in a .PNG file. When I will distribute the block, I would prefer sharing only a Simulink file, and not the image.
To avoid the need to carry the image file, it is possible to associate the image data with the block.
It is important to explicitly make the UserData persistent, otherwise it will not be saved with the model. I also like to make the UserData a structure. That way if someone else wants to save data there, it will be possible to create a new field.
Once this is done, the image data will stay with the block. You can copy it to a different subsystem or to a new model, it will remain associated with the block.
Once the data is associated with the block, you can retrieve it in the mask icon drawing commands, and display it:
Now it's your turn
How are you displaying images in your masked subsystems? Let us know by leaving a comment below.
要发表评论，请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。