Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <System.Runtime.InteropServices.DllImport("gdiplus.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Unicode)>
  2. Friend Shared Function GdipSaveImageToFile(image As IntPtr, filename As String, <System.Runtime.InteropServices.[In]> ByRef clsid As Guid, encparams As IntPtr) As Integer
  3. End Function
  4.  
  5. Sub test(hbmp as IntPtr, filename as String, clsid as Guid)
  6. Dim status as Integer = GdipSaveImageToFile(hbmp, filename, clsid, IntPtr.Zero)
  7. If status <> 0 Then
  8. MessageBox.Show("Error status = " & status)
  9. End If
  10. End Sub
  11.  
  12. <System.Runtime.InteropServices.DllImport("gdiplus.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Unicode)>
  13. Friend Shared Function GdipSaveImageToFile(image As IntPtr, filename As String, <System.Runtime.InteropServices.[In]> ByRef clsid As Guid, ByRef encparams As cEncoderParameters) As Integer
  14. End Function
  15.  
  16. <StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)>
  17. Friend Structure cEncoderParameter
  18. Public GUID As Guid
  19. Public NumberOfValues As UInt32
  20. Public type As UInt32
  21. Public Value As IntPtr
  22. End Structure
  23.  
  24. <StructLayout(LayoutKind.Sequential, Pack:=2)>
  25. Friend Class cEncoderParameters
  26. Public Count As UInt32
  27. Public Parameter As cEncoderParameter
  28. End Class
  29. Friend Enum cEncoderParameterType As UInt32
  30. EncoderParameterValueTypeByte = 1 ' 8-bit unsigned int
  31. EncoderParameterValueTypeASCII = 2 ' 8-bit byte containing one 7-bit ASCII code. NULL terminated.
  32. EncoderParameterValueTypeShort = 3 ' 16-bit unsigned int
  33. EncoderParameterValueTypeLong = 4 ' 32-bit unsigned int
  34. EncoderParameterValueTypeRational = 5 ' Two Longs. The first Long Is the numerator, the second Long expresses the denomintor.
  35. EncoderParameterValueTypeLongRange = 6 ' Two longs which specify a range of integer values. The first Long specifies the
  36. ' lower end And the second one specifies the higher end. All values are inclusive at both ends
  37. EncoderParameterValueTypeUndefined = 7 ' 8-bit byte that can take any value depending on field definition
  38. EncoderParameterValueTypeRationalRange = 8 ' Two Rationals. The first Rational specifies the lower end And the second specifies
  39. ' the higher end. All values are inclusive at both ends
  40. EncoderParameterValueTypePointer = 9 ' A pointer to a parameter defined data.
  41. End Enum
  42.  
  43. Sub b(hbmp As IntPtr, filename As String, clsid As Guid)
  44. Dim eps As New cEncoderParameters
  45. eps.Count = 1
  46. eps.Parameter.GUID = Encoder.Quality.Guid
  47. eps.Parameter.NumberOfValues = 1
  48. eps.Parameter.type = cEncoderParameterType.EncoderParameterValueTypeLong
  49. eps.Parameter.Value = New IntPtr(10)
  50.  
  51. If GdipSaveImageToFile(hbmp, filename, clsid, eps) <> 0 Then
  52. MessageBox.Show("Error")
  53. End If
  54. End Sub
  55.  
  56. Dim pEnc As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(eps))
  57. Marshal.StructureToPtr(eps, pEnc, False)
  58.  
  59. status = GdipSaveImageToFile(hbmp, filename, clsid, pEnc)
  60.  
  61. Marshal.FreeHGlobal(pEnc)
  62.  
  63. class EncoderParameter
  64. {
  65. public:
  66. GUID Guid; // GUID of the parameter
  67. ULONG NumberOfValues; // Number of the parameter values
  68. ULONG Type; // Value type, like ValueTypeLONG etc.
  69. VOID* Value; // A pointer to the parameter values
  70. };
  71.  
  72. class EncoderParameters
  73. {
  74. public:
  75. UINT Count; // Number of parameters in this structure
  76. EncoderParameter Parameter[1]; // Parameter values
  77. };
  78.  
  79. GpStatus WINGDIPAPI
  80. GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
  81. GDIPCONST CLSID* clsidEncoder,
  82. GDIPCONST EncoderParameters* encoderParams);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement