News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Converting bmp to jpg?

Started by Farabi, July 20, 2008, 12:52:08 PM

Previous topic - Next topic

Farabi

Is windows have library to convert bmp to jpg?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dsouza123

The closest thing I could find for bmp and jpeg handling/conversion is using gdiplus (gdi+)
the gdiplus.dll comes with XP and is available for earlier Windows versions.

GDI+: bmp/gif/png/jpg to bmp/gif/png/jpg
http://www.masm32.com/board/index.php?topic=5210.msg38936

Using GDI+ (GDIplus)
http://www.masm32.com/board/index.php?topic=5673.msg52290

Loading JPEG as splash
http://www.masm32.com/board/index.php?topic=5348.msg40077

MichaelW

The attachment is another example that uses GDI+.


[attachment deleted by admin]
eschew obfuscation

Farabi

Quote from: MichaelW on July 20, 2008, 08:16:33 PM
The attachment is another example that uses GDI+.


Thanks, this is just what I need.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Quote from: MichaelW on July 20, 2008, 08:16:33 PM
The attachment is another example that uses GDI+.

Where is the include file and the lib?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dsouza123

Two versions of the lib are available from this post for download, then use l2inc to generate the inc.

Put gdiplus.lib in your lib directory.
Go into your include directory and run l2inc pathtolib\gdiplus.lib
The gdiplus.inc will then reside in the include directory.

http://www.masm32.com/board/index.php?topic=6569.msg48859

Farabi

Hi,
I got a new problem, but I think I know where is the problem is but dont know how to solve it.\

Quote
   gdipsi              GdiplusStartupInput <1>  ; version must be 1
   token               dd 0
   image               dd 0
   numEncoders         dd 0
    sizeImageCodecInfo  dd 0
    pImageCodecInfo     dd 0
   
.code

fPicSaveToFileAsJpg proc uses esi edi lpFileName:dword
   LOCAL str_len,tmp_esi:dword
   LOCAL buff[256],buff2[256],buff3[256]:dword
   
   invoke exist,lpFileName
   .if eax==0
      invoke MessageBox,0,0,0,0
      ret
   .endif
   
   invoke GdiplusStartup, ADDR token, ADDR gdipsi, NULL
      invoke GdipLoadImageFromFile, lpFileName, ADDR image
      invoke GdipGetImageEncodersSize, ADDR numEncoders,ADDR sizeImageCodecInfo
      invoke mAlloc,sizeImageCodecInfo
      .if eax==0
         invoke MessageBox,0,CADD("Not Enough memory/Memori tidak cukup"),0,0
         jmp error
      .endif
      mov pImageCodecInfo,eax
      invoke GdipGetImageEncoders, numEncoders, sizeImageCodecInfo,pImageCodecInfo
            invoke lstrlen,lpFileName
            mov str_len,eax
            sub str_len,2
            invoke lstrcpyn,addr buff,lpFileName,str_len
            invoke lstrcat,addr buff,CADD("jpg")
            
            assume esi:ptr ImageCodecInfo
               mov ecx,numEncoders
               mov esi,pImageCodecInfo
               @@:
               push ecx
               push esi
               mov tmp_esi,esi
               invoke WideCharToMultiByte,0,0,[esi].MimeType,-1,addr buff2,1024,0,0
               invoke lstrcmp,addr buff2,CADD("image/jpeg")
               .if eax==0
                  invoke MultiByteToWideChar,0,0,addr buff,-1,addr buff3,1024
                  invoke GdipSaveImageToFile, image, addr buff3,tmp_esi, NULL

                  
                  jmp error
               .endif
               pop esi
               add esi, SIZEOF ImageCodecInfo
               pop ecx
               dec ecx
               jnz @b
            assume esi:nothing
      
      error:      
   invoke GdipDisposeImage, image
   invoke GdiplusShutdown, token
   invoke GlobalFree,pImageCodecInfo
   
   ret
fPicSaveToFileAsJpg endp


The red color is what I think the problem is. Everything I think work fine except for those 2 function. I did not generate any file. Anyone can help?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

MichaelW

Farabi,

I should have added a note that the import library and include file are in the MASM32 version 10 beta, but not in the earlier versions.

If I pass your procedure the correct filename as an ANSI string then GdipLoadImageFromFile fails because it expects a Unicode string. If I pass your procedure the correct filename as a Unicode string, then after I comment out the invoke exist,lpFileName code, and replace the call to mAlloc with the alloc macro, the code works OK except the output file is named "sjpg".
eschew obfuscation

Farabi

Okay, I solve the problem, thanks MichaelW.
Quote
fPicSaveToFileAsJpg proc uses esi edi lpFileName:dword
   LOCAL str_len,tmp_esi:dword
   LOCAL buff[256],buff2[256],buff3[256]:dword
   
   invoke exist,lpFileName
   .if eax==0
      invoke MessageBox,0,0,0,0
      ret
   .endif
   
   invoke GdiplusStartup, ADDR token, ADDR gdipsi, NULL
      invoke MultiByteToWideChar,0,0,lpFileName,-1,addr buff3,1024
      invoke GdipLoadImageFromFile, addr buff3, ADDR image
      invoke GdipGetImageEncodersSize, ADDR numEncoders,ADDR sizeImageCodecInfo
      invoke mAlloc,sizeImageCodecInfo
      .if eax==0
         invoke MessageBox,0,CADD("Not Enough memory/Memori tidak cukup"),0,0
         jmp error
      .endif
      mov pImageCodecInfo,eax
      invoke GdipGetImageEncoders, numEncoders, sizeImageCodecInfo,pImageCodecInfo
            invoke lstrlen,lpFileName
            mov str_len,eax
            sub str_len,2
            invoke lstrcpyn,addr buff,lpFileName,str_len
            invoke lstrcat,addr buff,CADD("jpg")
            
            assume esi:ptr ImageCodecInfo
               mov ecx,numEncoders
               mov esi,pImageCodecInfo
               @@:
               push ecx
               push esi
               mov tmp_esi,esi
               invoke WideCharToMultiByte,0,0,[esi].MimeType,-1,addr buff2,1024,0,0
               invoke lstrcmp,addr buff2,CADD("image/jpeg")
               .if eax==0
                  invoke MultiByteToWideChar,0,0,addr buff,-1,addr buff3,1024
                  invoke GdipSaveImageToFile, image, addr buff3,tmp_esi, NULL
                  pop esi
                                                pop ecx
                  jmp error
               .endif
               pop esi
               add esi, SIZEOF ImageCodecInfo
               pop ecx
               dec ecx
               jnz @b
            assume esi:nothing
      
      error:      
   invoke GdipDisposeImage, image
   invoke GdiplusShutdown, token
   invoke GlobalFree,pImageCodecInfo
   
   ret
fPicSaveToFileAsJpg endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"