Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Reading JPEGs

alfredwodell
Beginner
576 Views
I want to be able to read a JPG file and convert it
to a bitmap in memory.
Can anyone help please?
0 Kudos
1 Reply
lcorona
Beginner
576 Views
Yo can use FreeimageX, an activex control you can download from freeimage.sf.net.

You must register it with regsvr32.exe and then use the module wizzard to create all the com interfaces avaliable.

The following is a subroutine I use to convert from bmp to png. To convert from jpg to bmp is easy to accomplish, the variable archivo must be of the form "imagen.jpg" and the variable archivo_png as "imagen.bmp". You may ignore the call to $IImage_ChangeColors.

subroutine bmp2png( archivo )
  use dfcom, only: COMInitialize, COMUnInitialize, COMCreateObjectByProgID
  use dflib, only: delfilesqq
  use FreeImage, only: $IImage_Open, $IImage_Save, $IImage_Close, $IImage_ChangeColors
  implicit none
  character, intent(in) :: ARCHIVO*(*)
  character(4096) :: archivo_png
  integer(4) objeto
  integer(4) retint
  integer(2) retsuccess
  integer(4) status

  archivo_png=archivo(1:len_trim(archivo)-3)
  archivo_png=trim(archivo_png)//'png'

  call cominitialize (status)
  CALL COMCreateObjectByProgID ('FreeImage.Image', objeto, status) 

  retint = $IImage_Open(objeto, archivo, retsuccess)

  if(retsuccess == 1) then
    retint = $IImage_ChangeColors(objeto, int(24), int(1), retsuccess)
    if(retsuccess /= 0) then
      retint = $IImage_Save(objeto, archivo_png, retsuccess)
      retint = $IImage_Close(objeto)
      if(retsuccess == 1) retint = delfilesqq(archivo)
    end if
  end if
  CALL COMUninitialize ()
end subroutine bmp2png


Len
0 Kudos
Reply