I have the same problem , i need convert a BMP into a JPG , i translate the
code of sergey , but a have several error and crash when convert the
images, any idea , any solution ,i'm desesperate.
Best Regards
Bmp_2_JPG_From_File("test.bmp","test.jpg")
Private Sub Bmp_2_JPG_From_File(ByVal cFicheroIn As String, ByVal
cFicheroOut As String)
Dim bmp As IntPtr = SHLoadImageFile(cFicheroIn)
ARM_WriteBitmapIntoJpegFile(cFicheroOut, 90, bmp)
End Sub
<DllImport("coredll.dll", SetLastError:=True)> _
Private Shared Function LoadLibrary(ByVal dllFile As String) As IntPtr
End Function
<DllImport("coredll.dll", SetLastError:=True)> _
Private Shared Function FreeLibrary(ByVal handle As IntPtr) As Boolean
End Function
<DllImport("aygshell.dll", EntryPoint:="#75", SetLastError:=True)> _
Public Shared Function SHLoadImageFile(ByVal szFileName As String) As IntPtr
End Function
<DllImport("coredll", SetLastError:=True)> _
Public Shared Function DeleteObject(ByVal hObject As IntPtr) As IntPtr
End Function
<DllImport("ARM_JpegLibThunk.dll", EnTryPoint:="WriteBitmapIntoJpegFile")> _
Private Function ARM_WriteBitmapIntoJpegFile(ByVal outFile As String, ByVal
quality As Integer, ByVal bitmap As IntPtr) As Boolean
End Function
<DllImport("ARM_JpegLibThunk.dll", EntryPoint:="WriteRGBBytesIntoJpegFile")>
_
Private Function ARM_WriteRGBBytesIntoJpegFile(ByVal outFile As String,
ByVal width As Integer, ByVal height As Integer, ByVal quality As Integer,
ByVal array As Byte) As Boolean
End Function
On Wed, 27 Apr 2005 12:37:17 +0300, Sergey Bogdanov wrote:
I was using SHLoadImageFile [1] just for simplicity. It loads image file
and returns its HBITMAP which I pass to WriteBitmapIntoJpegFile.
To convert byte array with image into JPG file you have to use
WriteRGBBytesIntoJpegFile P/Invoke. The last parameter is an array with
length equals to height * width * 3 (where 3 bytes is RGB). I have
updated JpegTest [2] now it also demonstrates how to use
WriteRGBBytesIntoJpegFile function.
It works great! THANKS A LOT!!!!!
Still havn't tried the in-memory way, but converting existing BMP files
ist really nice!
Boris