You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be really cool if we could add Part Type Icons to Label Templates. That would enable automatic generation of labels that look like the one below (but with vector based icons instead of images):
I've had a play with the code base, but I am hampered by a complete lack of C# and dot net experience, so i'm not sure i'll be able to figure out a complete solution by myself!
but when I watch partType in the debugger, it says icon is null. I was expecting this field to contain the icon's SVG data.
as a test, I created a new part type with a custom svg icon. This shows up in the PartType response. Good enough for now:
now i'm getting somewhere! next step is to convert the SVG into a graphic, and merge that with the label. For this I plan to use svg.skia.
Here's the function for converting SVGs to graphics and merging them:
privatevoidDrawIcon(CustomLabelDefinitionlabelDef,Image<Rgba32>image,LabelBoxbox,stringicon,floatx,floaty,floatwidth,floatheight){if(width==0||height==0)return;// Create an SKBitmap from the SVG textvarskSvg=new SKSvg();using(varsvgStream=new MemoryStream(System.Text.Encoding.UTF8.GetBytes(icon))){
skSvg.Load(svgStream);}varpicture= skSvg.Picture;if(picture==null)return;varbitmap=new SKBitmap((int)width,(int)height);using(varcanvas=new SKCanvas(bitmap)){
canvas.Clear(SKColors.Transparent);// Calculate the scale for the SVG to fit the specified width and heightvarscaleX=width/ picture.CullRect.Width;varscaleY=height/ picture.CullRect.Height;// Scale and draw the SVG
canvas.Scale(scaleX, scaleY);
canvas.DrawPicture(picture);}// Convert SKBitmap to ImageSharp Imageusing(varskiaImage= SKImage.FromBitmap(bitmap))using(vardata= skiaImage.Encode(SKEncodedImageFormat.Png,100))using(varms=new MemoryStream()){
data.SaveTo(ms);
ms.Seek(0, SeekOrigin.Begin);varsvgImage= Image.Load<Rgba32>(ms);// Draw the SVG image onto the original image
image.Mutate(c => c.DrawImage(svgImage,new Point((int)x +1,(int)y +1),new GraphicsOptions()));}}
and the result, very close to what I want!
Next to do is to get the aspect ratio right, and make sure the icons render correctly. They should also be black and white only, no grayscale.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
It would be really cool if we could add Part Type Icons to Label Templates. That would enable automatic generation of labels that look like the one below (but with vector based icons instead of images):
I've had a play with the code base, but I am hampered by a complete lack of C# and dot net experience, so i'm not sure i'll be able to figure out a complete solution by myself!
That gets me a Part Type Icon element that I can drag into the template editor:
I've added:
but when I watch partType in the debugger, it says icon is null. I was expecting this field to contain the icon's SVG data.
as a test, I created a new part type with a custom svg icon. This shows up in the PartType response. Good enough for now:
now i'm getting somewhere! next step is to convert the SVG into a graphic, and merge that with the label. For this I plan to use svg.skia.
Here's the function for converting SVGs to graphics and merging them:
and the result, very close to what I want!
Next to do is to get the aspect ratio right, and make sure the icons render correctly. They should also be black and white only, no grayscale.
Beta Was this translation helpful? Give feedback.
All reactions