Test bitmap for pixels

This forum is for eXpress++ general support.
Post Reply
Message
Author
c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Test bitmap for pixels

#1 Post 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




Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

psc
Posts: 5
Joined: Thu Sep 29, 2016 11:48 am

Re: Test bitmap for pixels

#2 Post 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

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Test bitmap for pixels

#3 Post by rdonnay »

I am thinking that GetPixel may not be the correct choice for you. It reads a pixel value from the visible screen.
The eXpress train is coming - and it has more cars.

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Test bitmap for pixels

#4 Post 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
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Test bitmap for pixels

#5 Post 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
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Test bitmap for pixels

#6 Post by rdonnay »

I really do not understand what it is that you are trying to accomplish.

Please clarify.
The eXpress train is coming - and it has more cars.

User avatar
TWolfe
Posts: 60
Joined: Thu Jan 28, 2010 7:34 am

Re: Test bitmap for pixels

#7 Post 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

c-tec
Posts: 379
Joined: Tue Apr 20, 2010 1:36 am
Location: SALZBURG/AUSTRIA
Contact:

Re: Test bitmap for pixels

#8 Post 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
Rudolf Reinthaler
digital pen & paper systems
http://www.formcommander.net

User avatar
Auge_Ohr
Posts: 1414
Joined: Wed Feb 24, 2010 3:44 pm

Re: Test bitmap for pixels

#9 Post 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() )
greetings by OHR
Jimmy

Post Reply