none
Why can not Grid cloned with childrens? RRS feed

  • Question

  • System.Windows.Markup.XamlParseException: ''No matching constructor found on type 'System.Windows.Media.Imaging.WriteableBitmap'

    Here bi - bitmapimage, im - image.

    Private Sub pelespausti(sender As Object, e As MouseButtonEventArgs) Handles Grid1.MouseDown
            If e.LeftButton = MouseButtonState.Pressed Then
                If im IsNot Nothing Then
                    If e.GetPosition(im).X >= im.Margin.Left AndAlso e.GetPosition(im).X < im.ActualWidth AndAlso
                    e.GetPosition(im).Y >= im.Margin.Top AndAlso e.GetPosition(im).Y < im.ActualHeight Then
                        'CType(bi.PixelWidth / 8, Integer)
                        Dim pix As PixelFormat = PixelFormats.Rgba64
                        Array.Resize(Of Byte)(pixels2, bi.PixelWidth * bi.PixelHeight * Math.Ceiling(pix.BitsPerPixel / 8))
    
                        colors = New List(Of System.Windows.Media.Color) From {System.Windows.Media.Colors.Transparent}
                        palete = New BitmapPalette(colors)
                        bi2 = BitmapSource.Create(bi.PixelWidth, bi.PixelHeight, 96, 96, pix, palete, pixels2, Math.Ceiling(bi.PixelWidth * pix.BitsPerPixel / 8))
    
                        o = New FormatConvertedBitmap(bi2, pix, palete, 100)
                        o2 = New FormatConvertedBitmap(bi, o.Format, palete, 100)
                        Dim pixelsp(Math.Ceiling(o2.Format.BitsPerPixel / 8)) As Byte
                        Dim pixelsp2(Math.Ceiling(o2.Format.BitsPerPixel / 8)) As Byte
                        o2.CopyPixels(New Int32Rect(e.GetPosition(im).X, e.GetPosition(im).Y, 1, 1), pixelsp, Math.Ceiling(o2.Format.BitsPerPixel / 8), 0) 'klaida
    
                        ras = New WriteableBitmap(o)
                        'Me.Title = Color.FromArgb(pixelsp(0), pixelsp(1), pixelsp(2), pixelsp(3)).R
                        Dim m As Boolean = True
                        For x = 0 To o2.PixelWidth - 1
                            For y = 0 To o2.PixelHeight - 1
                                o2.CopyPixels(New Int32Rect(x, y, 1, 1), pixelsp2, Math.Ceiling(o2.Format.BitsPerPixel / 8), 0)
                                For k = 0 To pixelsp.GetUpperBound(0)
                                    If Not pixelsp(k) = pixelsp2(k) Then
                                        m = False : Exit For
                                    End If
                                Next
                                If m = True Then
                                    ras.WritePixels(New Int32Rect(x, y, 1, 1), pixelsp2, Math.Ceiling(o.Format.BitsPerPixel / 8), 0)
                                Else
                                    m = True
                                End If
                            Next
                        Next
                        im.Source = ras
    
                        Me.Title = "komp"
                    End If
                End If
                Dim objXaml As String = Markup.XamlWriter.Save(Grid1)
                Dim StringReader As StringReader = New StringReader(objXaml)
                Dim xmlReader As Xml.XmlReader = Xml.XmlReader.Create(StringReader)
                Grid1 = Markup.XamlReader.Load(xmlReader)'here exception
            End If
    End Sub

    Friday, November 30, 2018 2:29 PM

All replies