<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code set image does not respect size in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14136859#M86888</link>
    <description>&lt;P&gt;To manually adjust the size&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Bitmap resizedBitmap = new Bitmap(originBitmap.GetThumbailImage(width,height,null,Intptr.zero);&lt;/LI-CODE&gt;&lt;P&gt;The size is related to your screen's scale, meaning the&amp;nbsp; width &amp;amp; height must be multiplied by this scale factor to get the final size.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var scale = Graphics.FromHwnd(Application.MainWindow.Handle).DpiX/96f;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;then&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var bi = new BitmapImage();
bi.BeginInit();
using var ms = new MemoryStream();
resizedBitMap.Save(ms,ImageFormat.Png);
ms.Seek(0,SeekOrigin.Begin);
bi.StreamSource = ms;
bi.CacheOption = BitmapCaccheOption.OnLoad;
bi.EndInit();
ribbonButton.Image = bi;&lt;/LI-CODE&gt;&lt;P&gt;The code above was written without an IDE ,&amp;nbsp; if you spot any errors, feel free to tweak it a bit.&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2026 03:35:32 GMT</pubDate>
    <dc:creator>DYH_</dc:creator>
    <dc:date>2026-05-21T03:35:32Z</dc:date>
    <item>
      <title>Code set image does not respect size</title>
      <link>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14136159#M86884</link>
      <description>&lt;P&gt;Hello, i am trying to change the icon of a ribbon button at runtime, even tho it works, it tries to display the icon as a 32x32 instead of 16x16, button is created via cui editor and set to SmallWithText,&amp;nbsp; and icon is set from a function called from a command like following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;ribbon&lt;/SPAN&gt; = &lt;SPAN&gt;ComponentManager&lt;/SPAN&gt;.Ribbon;
            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;togglePipingModeButton&lt;/SPAN&gt; = &lt;SPAN&gt;ribbon&lt;/SPAN&gt;?.&lt;SPAN&gt;FindItem&lt;/SPAN&gt;(&lt;SPAN&gt;"TogglePipingModeButton"&lt;/SPAN&gt;, &lt;SPAN&gt;false&lt;/SPAN&gt;) &lt;SPAN&gt;as&lt;/SPAN&gt; &lt;SPAN&gt;RibbonButton&lt;/SPAN&gt;;

            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;isDarkTheme&lt;/SPAN&gt; = &lt;SPAN&gt;Application&lt;/SPAN&gt;.&lt;SPAN&gt;GetSystemVariable&lt;/SPAN&gt;(&lt;SPAN&gt;"COLORTHEME"&lt;/SPAN&gt;).&lt;SPAN&gt;ToString&lt;/SPAN&gt;() == &lt;SPAN&gt;"0"&lt;/SPAN&gt;;
            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;imageName&lt;/SPAN&gt; = &lt;SPAN&gt;PipCmnApp&lt;/SPAN&gt;.&lt;SPAN&gt;PipingCommonSettings&lt;/SPAN&gt;.AdvancedPipingMode ? (&lt;SPAN&gt;isDarkTheme&lt;/SPAN&gt; ? &lt;SPAN&gt;"advancedpipingmode_dark"&lt;/SPAN&gt; : &lt;SPAN&gt;"advancedpipingmode_light"&lt;/SPAN&gt;) : (&lt;SPAN&gt;isDarkTheme&lt;/SPAN&gt; ? &lt;SPAN&gt;"simplepipingmode_dark"&lt;/SPAN&gt; : &lt;SPAN&gt;"simplepipingmode_light"&lt;/SPAN&gt;);
            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;uri&lt;/SPAN&gt; = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;Uri&lt;/SPAN&gt;(&lt;SPAN&gt;$"pack://application:,,,/PipCmn;component/Resources/ribbon/&lt;/SPAN&gt;{&lt;SPAN&gt;imageName&lt;/SPAN&gt;}&lt;SPAN&gt;.ico"&lt;/SPAN&gt;, &lt;SPAN&gt;UriKind&lt;/SPAN&gt;.Absolute);
            &lt;SPAN&gt;togglePipingModeButton&lt;/SPAN&gt;.Size = &lt;SPAN&gt;RibbonItemSize&lt;/SPAN&gt;.Standard;

            &lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;image&lt;/SPAN&gt; = &lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;BitmapImage&lt;/SPAN&gt;(&lt;SPAN&gt;uri&lt;/SPAN&gt;);

            &lt;SPAN&gt;togglePipingModeButton&lt;/SPAN&gt;.Image = &lt;SPAN&gt;image&lt;/SPAN&gt;;
            &lt;SPAN&gt;togglePipingModeButton&lt;/SPAN&gt;.Text = &lt;SPAN&gt;PipCmnApp&lt;/SPAN&gt;.&lt;SPAN&gt;PipingCommonSettings&lt;/SPAN&gt;.AdvancedPipingMode ? &lt;SPAN&gt;"Modalità Avanzata"&lt;/SPAN&gt; : &lt;SPAN&gt;"Modalità Semplificata"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;this does indeed change the icon as said before, but as said, only shows the top-left "quadrant" of the 32x icon instead of scaling it to 16x&lt;BR /&gt;&lt;BR /&gt;tried this with both 16x png and 32x png and had the same result, tried switching to ico but nothing changed.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2026 15:00:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14136159#M86884</guid>
      <dc:creator>m_benigno</dc:creator>
      <dc:date>2026-05-20T15:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Code set image does not respect size</title>
      <link>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14136859#M86888</link>
      <description>&lt;P&gt;To manually adjust the size&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Bitmap resizedBitmap = new Bitmap(originBitmap.GetThumbailImage(width,height,null,Intptr.zero);&lt;/LI-CODE&gt;&lt;P&gt;The size is related to your screen's scale, meaning the&amp;nbsp; width &amp;amp; height must be multiplied by this scale factor to get the final size.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var scale = Graphics.FromHwnd(Application.MainWindow.Handle).DpiX/96f;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;then&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var bi = new BitmapImage();
bi.BeginInit();
using var ms = new MemoryStream();
resizedBitMap.Save(ms,ImageFormat.Png);
ms.Seek(0,SeekOrigin.Begin);
bi.StreamSource = ms;
bi.CacheOption = BitmapCaccheOption.OnLoad;
bi.EndInit();
ribbonButton.Image = bi;&lt;/LI-CODE&gt;&lt;P&gt;The code above was written without an IDE ,&amp;nbsp; if you spot any errors, feel free to tweak it a bit.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2026 03:35:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14136859#M86888</guid>
      <dc:creator>DYH_</dc:creator>
      <dc:date>2026-05-21T03:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Code set image does not respect size</title>
      <link>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14137040#M86890</link>
      <description>&lt;P&gt;It did indeed work, a shame tho that i have to manually adjust the size even tho the icon is already in the desired size.&lt;BR /&gt;Nonetheless thanks for the answer!&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2026 07:12:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/code-set-image-does-not-respect-size/m-p/14137040#M86890</guid>
      <dc:creator>m_benigno</dc:creator>
      <dc:date>2026-05-21T07:12:02Z</dc:date>
    </item>
  </channel>
</rss>

