Конвертация в JPEG,TGA,PCX из PICTUREBOX
#37156686
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Не получается сделать так, чтобы из Picture1.hDC сразу конвертировать в JPEG. Файл создается, а в нём какой-то чёрный квадрат. Из DIB-секции я смог сконвертировать - это GdipCreateBitmapFromGdiDib, а как из HDC сконвертировать? Какие функции нужно использовать и причём тут SelectObject? Пример в аттаче.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76.
Option Explicit
Private Type GUID
data1 As Long
data2 As Integer
data3 As Integer
data4( 0 To 7 ) As Byte
End Type
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Type GdiplusStartupOutput
NotificationHook As Long
NotificationUnhook As Long
End Type
Private Type EncoderParameter
GUID As GUID
NumberOfValues As Long
type As Long
Value As Long
End Type
Private Type EncoderParameters
count As Long
Parameter As EncoderParameter
End Type
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hdc As Long, hGraphics As Long) As Long
Private Declare Function GdipCreateBitmapFromGraphics Lib "gdiplus" (ByVal Width As Long, ByVal Height As Long, ByVal Graphics As Long, bitmap As Long) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, outputbuf As GdiplusStartupOutput) As Long
Private Declare Function GdipSaveImageToFile Lib "gdiplus" (ByVal image As Long, ByVal FileName As Long, clsidEncoder As GUID, encoderParams As Any) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal image As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal hGraphics As Long) As Long
Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As Long
Private Const EncoderParameterValueTypeLong = 4
Private Sub Command1_Click()
Dim Graphics As Long
Dim encoderCLSID As GUID
Dim gdiSI As GdiplusStartupInput
Dim gdiSO As GdiplusStartupOutput
Dim lGDIP As Long
Dim TParams As EncoderParameters
Dim lBmp As Long
gdiSI.GdiplusVersion = 1
Call GdiplusStartup(lGDIP, gdiSI, gdiSO)
Call GdipCreateFromHDC(Picture1.hdc, Graphics)
Call GdipCreateBitmapFromGraphics( 256 , 256 , Graphics, lBmp)
Call CLSIDFromString(StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), encoderCLSID)
TParams.count = 1
With TParams.Parameter
Call CLSIDFromString(StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID)
.NumberOfValues = 1
.type = EncoderParameterValueTypeLong
.Value = VarPtr( 100 )
End With
Call GdipSaveImageToFile(lBmp, StrPtr(App.Path & "\lBmp.jpg"), encoderCLSID, TParams)
Call GdipDisposeImage(lBmp)
Call GdipDeleteGraphics(Graphics)
Call GdiplusShutdown(lGDIP)
End Sub
|
|