Using Utils.GetBlockImage() for RibbonButton image

Using Utils.GetBlockImage() for RibbonButton image

Anonymous
Not applicable
974 Views
2 Replies
Message 1 of 3

Using Utils.GetBlockImage() for RibbonButton image

Anonymous
Not applicable

I'm trying to use the Autodesk.AutoCAD.Internal.Utils.GetBlockImage() method to get a preview of the blocks of a closed document. However, when using System.Windows.Interop.Imaging.CreateBitmapSourceFromHitmap(), the image in the RibbonSplitButton does not display correctly. How can I convert and resize it to display it correctly in the RibbonSplitButton?

0 Likes
975 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Oh, just used nImgWidth = 32 and nImgHeight = 32 along with System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions() for System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap() and it worked
0 Likes
Message 3 of 3

norman.yuan
Mentor
Mentor

Have you tried to pass different width/height values to the GetBlockImage() method?

 

Since you need image for the Ribbon UI, which does not need higher qualify/resolution images, and I guess you need them at runtime, you might want to try

 

Autodesk.AutoCAD.Windows.Data.CMLContentSearchPreviews class (in acmgd.dll), it has a static method GetBlockTRThumbnail(BlockTableRecord). This method is designed for AutoCAD to get a block's thumbnail for AutoCAD's UI at runtime, so it could be just what you want. The good thing is that it directly generate the thumbnail image as ImageSource, so you do not need code to convert bitmap to ImageSource for AutoCAD UI use.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes