Deployment/debugging issues after including BitmapResource in project

Has anyone noticed odd behavior when your project includes a BitmapResource?

I am using a SCM20260E with the latest 2.2.2.1000 firmware. Everything works fine, but when I add a PNG as a BitmapResource in Resources.resx, I start to have odd behavior. Visual Studio 2022 no longer goes through the same process of “Generating device specific assemblies” and “Incrementally deploying assemblies to the device” line-by-line. Instead, it skips that and much more quickly goes straight to the debugger. Where things get really weird is that the debugger runs, but it is running OLD code. Any changes that I made to the source code after adding the BitmapResource have not taken effect, even though they are shown on the screen. The debugger appears to step through the new source code, but it is actually executing whatever statement was on that same line number from the last time it deployed the assemblies, i.e. before adding the BitmapResource to the project. I know it sounds crazy, but it is very repeatable.

2 Likes

What I described above does NOT happen if the resource is a JPEG, so that is both a clue as to what is going on and a workaround.

I’d still like to fix this, because I’d like to use transparency in my image.

PNG are not supported but when you create a bitmap object, you can pick one single color to be transparent. I forgot the property name.

You can use this example as a starting point. This is the stripped down code for the UI element that works for me.

using System.Drawing;
using GHIElectronics.TinyCLR.UI;
using GHIElectronics.TinyCLR.UI.Media;
using GHIElectronics.TinyCLR.UI.Media.Imaging;
using Color = System.Drawing.Color;

namespace YourNamespace.TinyCLR.UI.Media
{
    class TransparentElement : UIElement
    {
        private readonly BitmapImage _bitmapImage;

        public TransparentElement(Bitmap bitmap, Color transparentColor)
        {
            this.Width  = bitmap.Width;
            this.Height = bitmap.Height;

            Graphics graphics = Graphics.FromImage(bitmap);
            graphics.MakeTransparent(transparentColor);
            this._bitmapImage = BitmapImage.FromGraphics(graphics);
            graphics.Dispose();
        }

        protected override void RenderRecursive(DrawingContext dc)
        {
            base.RenderRecursive(dc);
            GetLayoutOffset(out int x0, out int y0);
            dc.DrawImage(this._bitmapImage, x0, y0);
        }
    }
}

Initial implementation from GHI here: “Official Demos/SCM20260D Dev/Utils/Icon.cs

2 Likes

Thanks, I will try this instead of the PNGs.

Yeah, in my experience if you add an image to the resources and then try to change the file type it will crater the ability to reflash the program. Best to use an online converter and make any image type a bitmap first, then resize it/modify it the way you want, THEN add it to the resources as an image.