How get DPI ?

How get DPI ?

Postby Romeo » Mon Feb 22, 2010 5:42 pm

Hi,

i simple need to get (a runtime) a DPI of a generic file (logo.bmp).

It will resolve all my big (?!) problem ?

Any simple help ?

tks
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How get DPI ?

Postby StefanHaupt » Tue Feb 23, 2010 8:10 am

Romeo,

here is a function to read some properties of bmp files. Maybe it´s usefull for you.

Code: Select all  Expand view
#define TAB Chr(9)
//-------------------------------------------------------------------//
FUNCTION BmpInfo (nH, cBmp)

  LOCAL i, cInfo := ""
  LOCAL aInfoText := {"Bitmaptype"+TAB+": ",;//       : ",;
                      "Size"+TAB+TAB+": ",;//             : ",;
                      "reserved"+TAB+TAB+": ",;//         :",;
                      "reserved"+TAB+TAB+": ",;//         :",;
                      "Data offset"+TAB+": ",;//      : ",;
                      "Header Size"+TAB+": ",;//      : ",;
                      "Width"+TAB+TAB+": ",;//            : ",;
                      "Height"+TAB+TAB+": ",;//           : ",;
                      "No planes"+TAB+": ",;//        : ",;
                      "Bits/pixel"+TAB+TAB+": ",;//       : ",;
                      "Compression"+TAB+": ",;//      : ",;
                      "Image Data size"+TAB+": ",;//  : ",;
                      "horz. pixel/meter"+TAB+": ",;//: ",;
                      "Vert. pixel/meter"+TAB+": ",;//: ",;
                      "No of colors"+TAB+": ",;//     : ",;
                      "Important colors"+TAB+": "  }

  aInfo := Array (20)

  IF nH > 0

    aInfo[1] := Chr (FReadByte (nH, 0, 1)) +;   // Typ
                Chr (FReadByte (nH, 1, 1))
    aInfo[2] := FReadByte (nH, 2,4)    // Filesize
    aInfo[3] := FReadByte (nH, 6,2)    // reserved, 0
    aInfo[4] := FReadByte (nH, 8,2)
    aInfo[5] := FReadByte (nH, 10,4)   // Data offset
    aInfo[6] := FReadByte (nH, 14,4)    // size of BitmapInfoHeader
    aInfo[7] := FReadByte (nH, 18,4)    // width
    aInfo[8] := FReadByte (nH, 22,4)    // height
    aInfo[9] := FReadByte (nH, 26,2)    // no of planes, must be 0
    aInfo[10] := FReadByte (nH, 28,2)   // no of bits / pixel
    aInfo[11] := FReadByte (nH, 30,4)   // compression type
    aInfo[12] := FReadByte (nH, 34,4)   // size of image dat in bytes, 0 when no compression
    aInfo[13] := FReadByte (nH, 38,4)   // horz. pixel / meter
    aInfo[14] := FReadByte (nH, 44,4)   // vert. pixerl / meter
    aInfo[15] := FReadByte (nH, 46,4)   // no of colors
    aInfo[16] := FReadByte (nH, 50,4)   // no of important colors
    //aInfo{17] := FReadByte (nH, 54,4)   //

    cInfo := cBmp+CRLF
    FOR i := 1 TO 16
      cInfo += aInfoText[i]+cValToChar (aInfo[i])+CRLF
    NEXT

  ENDIF

RETURN (cInfo)



//-------------------------------------------------------------------//
FUNCTION FReadByte (nH, nOffset, nLen, lHex)

  LOCAL i, cBuffer, xByte, nByte

  DEFAULT lHex := .f.  // return hex numbers

  FSeek (nH, nOffset, 0)
  cBuffer := Space (nLen)
  FRead (nH, @cBuffer, nLen)
  IF nLen = 4  // 32 bit
    nByte := Bin2L (cBuffer)
  ELSE
    nByte := Bin2I (cBuffer)
  ENDIF

  xByte := IIF (!lHex, nByte, Lower (DecToHex (nByte)) )
  IF lHex
    IF Len(xByte)<2
      xByte := "0"+xByte
    ENDIF
  ENDIF

RETURN (xByte)
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: How get DPI ?

Postby Romeo » Tue Feb 23, 2010 2:04 pm

Tks for the program,
but i'm not able to use it.

For example i dont know wath means the "nH" parameter in FUNCTION BmpInfo (nH, cBmp)

Anyway i understand that the informatio i'm looking for, are placed in the header of graphics files.

Hi
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How get DPI ?

Postby StefanHaupt » Wed Feb 24, 2010 8:30 am

Romeo,

nH is the handle of the open bmp-file, cBmp is the filename. Here is a sample, how to call it

Code: Select all  Expand view
FUNCTION Main ()

LOCAL hFile, cBmp

hFile := OpenBmp (@cBmp)

MsgInfo ( BmpInfo (hFile, cBmp) )

RETURN (nil)


//-------------------------------------------------------------------//
FUNCTION OpenBmp (cBmp)

  LOCAL hFile
  LOCAL cFile := cGetFile ("Bitmap|*.bmp","Open bitmap file",,,,.t.)

  IF !Empty (cFile)
    hFile := FOpen (cFile,0) // readonly
    cBmp := cFile
  ENDIF

RETURN (hFile)
 
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: How get DPI ?

Postby Romeo » Wed Feb 24, 2010 12:11 pm

Of course, tks
Romeo
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How get DPI ?

Postby Jonathan Hodder » Wed Feb 24, 2010 9:34 pm

Hi Stefan

I see this is for BMP files.

Do you have code to get header information for JPG files?

Thanks
Jonathan Hodder
 
Posts: 77
Joined: Sun Aug 26, 2007 11:53 pm

Re: How get DPI ?

Postby StefanHaupt » Thu Feb 25, 2010 8:35 am

Hi Jonathan,

I have this code only for bmp, sorry.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: How get DPI ?

Postby Jack » Thu Feb 25, 2010 7:57 pm

Is there the same function for JPEG files ??

Thanks
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: How get DPI ?

Postby StefanHaupt » Fri Feb 26, 2010 8:27 am

no, sorry, only for bmp
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests