Main Site Documentation

Glide for TinyCLR (first test, yay :)


#1

I need to access internal class Bitmap in System.Drawing.Internal. Any suggestion ?

How to do it without changing the official classes like System.Drawing…

I can compile the sample app but I cannot run it on the device because I need to add some changes in the official library and it’s not possible without GHI Team support :wink:

Thanks


#2

I am excited to see this. I wanted to do this before but couldn’t as a lot of needed drawing methods were missing but I think it can be done now.


#3

But, If I want to use those drawing methods from external library I need to access “surface” variable which is belong to System.Drawing.Internal.Bitmap class. we must put “[assembly:InternalsVisibleTo(“MyAssembly”)]” in AssemblyInfo.cs on GHIElectronics.TinyCLR.Drawing library.


#4

@Gus_Issa

Seems version 2.0 of TinyClrOS is going to finish before version 1.0 going on production…

LOL


#5

No no, I mean this v0.12 has them.


#6

There’s always reflection, but that’s accessing implementation details that can change, and in this case, will change sooner rather than later. That internal class will eventually go away completely. What methods are you missing that aren’t already exposed on the Graphics object?


#7

@mifmasterz : With a bit of refactoring you should be able to get quite a bit of it working using the new methods added to System.Drawing.Graphics in the 0.12 release. From memory I think you could do most of it by just editing the DrawingContext class (Don’t quote me on that!)


#8

I need these methods…

in Font.cs

Font.ComputeExtent

in Graphics.cs :

DrawEllipse(System.Drawing.Color colorOutline, int x, int y, int xRadius, int yRadius)

DrawEllipse(System.Drawing.Color colorOutline, int thicknessOutline, int x, int y, int xRadius, int yRadius, System.Drawing.Color colorGradientStart, int xGradientStart, int yGradientStart, System.Drawing.Color colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity)

DrawImage(int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height, ushort opacity)

DrawRectangle(System.Drawing.Color colorOutline, int thicknessOutline, int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, System.Drawing.Color colorGradientStart, int xGradientStart, int yGradientStart, System.Drawing.Color colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity)

DrawRectangle(Geom.Rectangle rect, System.Drawing.Color color, ushort opacity)

DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, uint dtFlags, System.Drawing.Color color, System.Drawing.Font font)

Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity)

SetClippingRectangle(int x, int y, int width, int height)

StretchImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity)

Thanks @John_Brochue :wink:


#9

You need to read through the old code and try and understand what each method is actually doing and then try and locate the equivalent method(s) on the new Graphics object.

For example:

DrawTextInRect = DrawString(RectangleF… etc)
Font.ComputeExtent = MeasureString(…)
StretchImage = DrawImage(Rectangle destRect, Rectangle srcRect… etc)
Scale9 = DrawImage + Some logic

Internally it’s using the old bitmap API so you should be able to work out most of it by decompiling the graphics class.

I imagine you will also need to do a bit of refactoring to take account of how the graphics class is created for the screen / bitmaps.

David


#10

Thanks @monoculture, this is really help… especially for MeasureString function.


#11

Your next problem will be getting touch events to work.

I haven’t tested this code but perhaps you could create a class that uses a thread to monitor the screens touch GPIOs and then raises an event when they change:

public class Touch
{
    private readonly GpioPin _x2Pin;
    private readonly GpioPin _y2Pin;
    private readonly GpioPin _x1Pin;
    private readonly GpioPin _y1Pin;

    private readonly AdcChannel _x1Adc;
    private readonly AdcChannel _y1Adc;

    public Touch()
    {
        var gpioController = GpioController.GetDefault();

        _x1Pin = gpioController.OpenPin(G120E.GpioPin.P0_23);
        _x2Pin = gpioController.OpenPin(G120E.GpioPin.P2_23);
        _y1Pin = gpioController.OpenPin(G120E.GpioPin.P0_24);
        _y2Pin = gpioController.OpenPin(G120E.GpioPin.P3_31);

        var adcController = AdcController.GetDefault();

        _x1Adc = adcController.OpenChannel(G120E.AdcChannel.P0_23);
        _y1Adc = adcController.OpenChannel(G120E.AdcChannel.P0_24);

        new Thread(Monitor).Start();
    }

    private void Monitor()
    {
        while (true)
        {
            //Read X

            _y1Pin.SetDriveMode(GpioPinDriveMode.Input);
            _y2Pin.SetDriveMode(GpioPinDriveMode.Input);
            _y2Pin.Write(GpioPinValue.Low);
            _x1Pin.SetDriveMode(GpioPinDriveMode.Output);
            _x1Pin.Write(GpioPinValue.High);
            _x2Pin.SetDriveMode(GpioPinDriveMode.Output);
            _x2Pin.Write(GpioPinValue.Low);

            var x = _y1Adc.ReadValue();

            // Read Y

            _x1Pin.SetDriveMode(GpioPinDriveMode.Input);
            _x2Pin.SetDriveMode(GpioPinDriveMode.Input);
            _x2Pin.Write(GpioPinValue.Low);
            _y1Pin.SetDriveMode(GpioPinDriveMode.Output);
            _y1Pin.Write(GpioPinValue.High);
            _y2Pin.SetDriveMode(GpioPinDriveMode.Output);
            _y2Pin.Write(GpioPinValue.Low);

            var y = _x1Adc.ReadValue();

            if (x != 0)
                Debug.WriteLine(x + "," + y);

            Thread.Sleep(10);
        }
    }
}

#12

As @monoculture was getting at, the old NETMF bitmap way of doing graphics has gone away. We’re aligning ourselves with what the other .NET platform APIs do for drawing (the System.Drawing namespace). So any code you port from NETMF will need to be updated to use the new style.

The previous release added a number of missing methods to the Graphics class to close the functionality gap from NETMF. One that is missing (as it had no immediate analog) is Scale9, that’ll need some more work on your end to replicate if you need that functionality.

If you’re having trouble figuring out the best replacement for a specific NETMF method, just let us know and we’ll try to get you going.


#13

This is the first test for Glide for TinyCLR… need more hands to fix a few bugs.

Grab it here: https://github.com/Gravicode/TinyCLR.Glide

Thanks @Gus_Issa @John_Brochue @monoculture


#14

Can’t wait to try it out.