Page 1 of 1

Test bitmap for pixels

Posted: Thu Sep 29, 2016 12:40 pm
by c-tec
Hello,
I have modified the pixelcolor sample to check for pixels in a bitmap. How can I prevent to show the dialog ? With hide I get no correct result, so it seems that the dialog must be visible.
regards
Rudolf

Code: Select all

#INCLUDE "dll.CH"
#INCLUDE "dcdialog.CH"

#define CRLF  chr(13) + CHR(10)
STATIC snHdll

FUNCTION Main()
******************************************************************
LOCAL GetList[0], GetOptions, oSay, hDC1, oStatic1, aPixel, oDlg

@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_BITMAP CAPTION "unterschrift1.bmp" OBJECT oStatic1 PREEVAL {|o|o:autoSize := .t.} ;
     EVAL {|o|hDC1 := GetWindowDC(o:getHWnd()),aPixel := Array(o:caption:xSize,o:caption:ySize)}

DCGETOPTIONS PIXEL

DCREAD GUI FIT OPTIONS GetOptions EVAL {||dc_guimemoedit(testpixel(hDC1,aPixel,oStatic1,oSay))} PARENT @oDlg
oDlg:destroy()

RETURN nil

* ---------


FUNCTION testpixel(hDC,aPixel,oStatic)
******************************************************************
LOCAL i, j, nXSize := Len(aPixel), nYSize := Len(aPixel[1]),cCheck := "",nFilled := 0,oScrn,nFail := 0,nTotal := 0,aColor,nColor,nStartRow ,nEndRow,cResponse := "",nStartCol,nEndCol,cImg := "",cChar := " "
oScrn := DC_WaitOn()

nStartRow := 1 //int(nYSize/2) //only one row for testing
nEndRow   := nYSize//int(nYSize/2)+1

nStartCol := 0
nEndCol   := nXSize

FOR i := nStartCol TO nEndCol
  FOR j := nStartRow to nEndRow
     cChar := " "
     nColor := GetPixel(hDC,i-1,j-1)
     if !empty(nColor)
          aColor := GraGetRGBIntensity(AutomationTranslateColor(nColor,.T.))
          if valtype(aColor) = "A"
               if aColor[1] # 255 .or. aColor[2] # 255 .or. aColor[3] # 255
                    nFilled++
                    cChar := "*"
               endif
          else
               cChar := "?"
               nFail++
               cResponse += ntrim(i) + " - " + ntrim(j) + " " + ntrim(nColor) + CRLF
          endif
          nTotal++
     else
          cChar := "-"
     endif
     cImg += cChar
  NEXT
  cImg += CRLF
NEXT
dc_impl(oScrn)
cResponse := "Size:" + ntrim(nXSize) + "x" + ntrim(nYSize) + CRLF + "Total:" + ntrim(nTotal) + CRLF + "Fail:" + ntrim(nFail) + CRLF + "Filled:" + ntrim(nFilled) + CRLF + cImg
return cResponse


function ntrim(n)
******************************************************************

return rtrim(ltrim(str(n,10,0)))



* ---------

PROC appsys ; RETURN

* ---------


#command  GDIFUNCTION <Func>([<x,...>]) ;
       => ;
FUNCTION <Func>([<x>]);;
STATIC scHCall := nil ;;
IF scHCall == nil ;;
  IF snHdll == nil ;;
    snHDll := DllLoad('GDI32.DLL') ;;
  ENDIF ;;
  scHCall := DllPrepareCall(snHDll,DLL_STDCALL,<(Func)>) ;;
ENDIF ;;
RETURN DllExecuteCall(scHCall,<x>)

GDIFUNCTION GetPixel( nHDC, x, y)
GDIFUNCTION SetPixel( nHDC, x, y, n )
DLLFUNCTION GetWindowDC( hwnd ) USING STDCALL FROM USER32.DLL





Re: Test bitmap for pixels

Posted: Fri Sep 30, 2016 4:37 pm
by psc
What are you trying to hide ?
For the progress bar, just uncomment oScrn ,

Code: Select all

//oScrn := DC_WaitOn() 
and

Code: Select all

//dc_impl(oScrn)
To not show the memoedit, you can do this:

instead of

Code: Select all

DCREAD GUI FIT OPTIONS GetOptions EVAL {|| dc_guimemoedit(testpixel(hDC1,aPixel,oStatic1,oSay))} PARENT @oDlg
use this

Code: Select all

DCREAD GUI FIT OPTIONS GetOptions EVAL {|| testpixel(hDC1,aPixel,oStatic1,oSay)} PARENT @oDlg
Now, if you want to hide the main window that contains the bitmap, do this:

Code: Select all

DCGETOPTIONS HIDE
DCREAD GUI FIT OPTIONS GetOptions EVAL {|| dc_guimemoedit(testpixel(hDC1,aPixel,oStatic1,oSay)) , oDlg:Show()} PARENT @oDlg
Note the second statement in the code block, the oDlg:Show()
You need this to show the main window after your processing so you can then close the application. If you leave it off, the window stays hidden, and running. Make sense ?

psc

Re: Test bitmap for pixels

Posted: Fri Sep 30, 2016 4:45 pm
by rdonnay
I am thinking that GetPixel may not be the correct choice for you. It reads a pixel value from the visible screen.

Re: Test bitmap for pixels

Posted: Sun Oct 02, 2016 12:34 am
by c-tec
Hello pcs,
I postes only a demo how I do this, dc_guimemoedit and dc_waiton() I only use for testing. As Roger wrote, this may not be the correct way to do this, but I have no other idea to solve it. It is so fast because reading only a few lines that I can live with the short display.
regards
Rudolf

Re: Test bitmap for pixels

Posted: Sun Oct 02, 2016 8:06 am
by Auge_Ohr
hi,

as i wrote in German Xbase++ Forum : why not compare o:SetBuffer() before / after ?

Code: Select all

   oldPic := oBitmap:Setbuffer()

   //
   // do some Code
   //
 
   newPic := oBitmap:Setbuffer()

   IF oldPic <> newPic
       // Picture have change
   ENDIF

Re: Test bitmap for pixels

Posted: Sun Oct 02, 2016 8:09 am
by rdonnay
I really do not understand what it is that you are trying to accomplish.

Please clarify.

Re: Test bitmap for pixels

Posted: Sun Oct 02, 2016 2:17 pm
by TWolfe
Rudolf,

Have you tried writing to an area outside the viewable screen area?

I have written apps that populate complex dialog screens outside the viewable desk-top and then move the dialog into the viewable screen. This works very well.

Terry

Re: Test bitmap for pixels

Posted: Mon Oct 03, 2016 12:03 am
by c-tec
Hello Jimmy, look at my answer in the german newsgroup. I have automatically to extract signature fields from PDFs in a background app that can contain not only the signature, also labes and pixels from borders and small other strokes. The position for extracting is also not exact that I get. So my method is neede to be sure that not wrong pixels are used for comparing.
I will try to use coordinates outside the window, maybe this works.
regards
Rudolf

Re: Test bitmap for pixels

Posted: Mon Oct 03, 2016 5:53 pm
by Auge_Ohr
c-tec wrote:I have automatically to extract signature fields from PDFs in a background app that can contain not only the signature, also labes and pixels from borders and small other strokes. The position for extracting is also not exact that I get. So my method is need to be sure that not wrong pixels are used for comparing.
i guess you use a Xbase++ XbpPresSpace() oPS.
i don't think you can compare 2 XbpPresSpace() but you can compare o:SetBuffer() -> String

you can make a Bitmap before/after from hole oPS not only where your Signature are which you try to extract ( o:Draw() / GraBitBlt() )