ibennz

Invoking ctor of image and saving to structure.

Jun 3rd, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.64 KB | None | 0 0
  1. Private Structure _bitmap
  2.         Public _Width As System.Reflection.MethodInfo
  3.         Public _Height As System.Reflection.MethodInfo
  4.         Public _GetPixel As System.Reflection.MethodInfo
  5.         Public _ctor As Reflection.ConstructorInfo
  6. End Structure
  7.  
  8. Private _reflected As _bitmap = Nothing
  9. Sub New()
  10.   'met toujours sa avent tout
  11.   Dim asm As Reflection.AssemblyName() = System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies()
  12.         For Each n As Reflection.AssemblyName In asm
  13.  
  14.             If (n.Name.ToLower() = "system.drawing") Then
  15.  
  16.                 Dim BitmapAssembly As Reflection.Assembly = Reflection.Assembly.Load(n)
  17.                 'test with the bitmap type
  18.                 Dim tbmp As Type = BitmapAssembly.GetType("System.Drawing.Bitmap")
  19.                 Dim ctor As Reflection.ConstructorInfo = tbmp.GetConstructor(New Type() {tbmp})
  20.                 'BackgroundImage = ctor.Invoke(New Object() {bmp})
  21.                 _reflected = New _bitmap()
  22.                 _reflected._Height = tbmp.GetMethod("Height")
  23.                 _reflected._Width = tbmp.GetMethod("Width")
  24.                 _reflected._GetPixel = tbmp.GetMethod("GetPixel")
  25.                 _reflected._ctor = ctor
  26.                 Exit For
  27.             End If
  28.  
  29.         Next
  30. End Sub
  31.  
  32. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  33.         'lets pretend this was loaded from resources , do not cast this to bitmap
  34.         Dim bmp As Object = Image.FromFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\1.bmp")
  35.  
  36.         BackgroundImage = _reflected._ctor.Invoke(New Object() {bmp})
  37. End Sub
Advertisement
Add Comment
Please, Sign In to add comment