Can't draw anything - help me !

Dec 13, 2014 at 6:36 PM
Edited Dec 13, 2014 at 6:38 PM
Hi !

I'm developping an app in which one i want to draw dynamically some shapes.
Someone told me to use WriteableBitmapEx which seems to fit with what i want to do.
However i cant draw anything, maybe i forgot an important line in my code ... I'm actually just testing a sample given here. See the code :

xaml :
<Grid Name="myGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <Image Name="myImage" Grid.Row="0" />
        <Button Grid.Row="1" Content="DRAW !" HorizontalAlignment="Center" Tapped="Button_Tapped"/>
        <TextBlock Grid.Row="2" Text="{Binding classString}" HorizontalAlignment="Center"/>
    </Grid>
and then i click on a button to draw some shapes, here is the code of the button :
c# :
private async void Button_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control
            WriteableBitmap writeableBmp = BitmapFactory.New(200, 200);
            writeableBmp.GetBitmapContext();

            // Clear the WriteableBitmap with white color
            writeableBmp.Clear(Colors.White);

            // Set the pixel at P(10, 13) to black
            writeableBmp.SetPixel(10, 13, Colors.Black);

            // Get the color of the pixel at P(30, 43)
            Color color = writeableBmp.GetPixel(30, 43);

            // Green line from P1(1, 2) to P2(30, 40)
            writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

            // Blue anti-aliased line from P1(10, 20) to P2(50, 70)
            writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue);

            // Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)
            writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

            // Red rectangle from the point P1(2, 4) that is 10px wide and 6px high
            writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

            // Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high
            writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

            // Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)
            int[] p = new int[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
            writeableBmp.DrawPolyline(p, Colors.Green);

            writeableBmp.Invalidate();

            myImage.Source = writeableBmp;


            //Creating instance for the MessageDialog Class  
            //and passing the message in it's Constructor  
            MessageDialog msgbox = new MessageDialog("Drew !");
            //Calling the Show method of MessageDialog class  
            //which will show the MessageBox  
            await msgbox.ShowAsync();

        }
and the messagebox appears properly.

Do you see what i'm missing ?

Atanakar.