Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <System.Runtime.InteropServices.DllImport("gdiplus.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Unicode)>
- Friend Shared Function GdipSaveImageToFile(image As IntPtr, filename As String, <System.Runtime.InteropServices.[In]> ByRef clsid As Guid, encparams As IntPtr) As Integer
- End Function
- Sub test(hbmp as IntPtr, filename as String, clsid as Guid)
- Dim status as Integer = GdipSaveImageToFile(hbmp, filename, clsid, IntPtr.Zero)
- If status <> 0 Then
- MessageBox.Show("Error status = " & status)
- End If
- End Sub
- <System.Runtime.InteropServices.DllImport("gdiplus.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Unicode)>
- Friend Shared Function GdipSaveImageToFile(image As IntPtr, filename As String, <System.Runtime.InteropServices.[In]> ByRef clsid As Guid, ByRef encparams As cEncoderParameters) As Integer
- End Function
- <StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)>
- Friend Structure cEncoderParameter
- Public GUID As Guid
- Public NumberOfValues As UInt32
- Public type As UInt32
- Public Value As IntPtr
- End Structure
- <StructLayout(LayoutKind.Sequential, Pack:=2)>
- Friend Class cEncoderParameters
- Public Count As UInt32
- Public Parameter As cEncoderParameter
- End Class
- Friend Enum cEncoderParameterType As UInt32
- EncoderParameterValueTypeByte = 1 ' 8-bit unsigned int
- EncoderParameterValueTypeASCII = 2 ' 8-bit byte containing one 7-bit ASCII code. NULL terminated.
- EncoderParameterValueTypeShort = 3 ' 16-bit unsigned int
- EncoderParameterValueTypeLong = 4 ' 32-bit unsigned int
- EncoderParameterValueTypeRational = 5 ' Two Longs. The first Long Is the numerator, the second Long expresses the denomintor.
- EncoderParameterValueTypeLongRange = 6 ' Two longs which specify a range of integer values. The first Long specifies the
- ' lower end And the second one specifies the higher end. All values are inclusive at both ends
- EncoderParameterValueTypeUndefined = 7 ' 8-bit byte that can take any value depending on field definition
- EncoderParameterValueTypeRationalRange = 8 ' Two Rationals. The first Rational specifies the lower end And the second specifies
- ' the higher end. All values are inclusive at both ends
- EncoderParameterValueTypePointer = 9 ' A pointer to a parameter defined data.
- End Enum
- Sub b(hbmp As IntPtr, filename As String, clsid As Guid)
- Dim eps As New cEncoderParameters
- eps.Count = 1
- eps.Parameter.GUID = Encoder.Quality.Guid
- eps.Parameter.NumberOfValues = 1
- eps.Parameter.type = cEncoderParameterType.EncoderParameterValueTypeLong
- eps.Parameter.Value = New IntPtr(10)
- If GdipSaveImageToFile(hbmp, filename, clsid, eps) <> 0 Then
- MessageBox.Show("Error")
- End If
- End Sub
- Dim pEnc As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(eps))
- Marshal.StructureToPtr(eps, pEnc, False)
- status = GdipSaveImageToFile(hbmp, filename, clsid, pEnc)
- Marshal.FreeHGlobal(pEnc)
- class EncoderParameter
- {
- public:
- GUID Guid; // GUID of the parameter
- ULONG NumberOfValues; // Number of the parameter values
- ULONG Type; // Value type, like ValueTypeLONG etc.
- VOID* Value; // A pointer to the parameter values
- };
- class EncoderParameters
- {
- public:
- UINT Count; // Number of parameters in this structure
- EncoderParameter Parameter[1]; // Parameter values
- };
- GpStatus WINGDIPAPI
- GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
- GDIPCONST CLSID* clsidEncoder,
- GDIPCONST EncoderParameters* encoderParams);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement