How to know the attributes of a pixel in the image

This forum is for general support of Xbase++
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: How to know the attributes of a pixel in the image

#11 Post by rdonnay »

That is very interesting. BTW - Do you ever sleep?

It never occurred to me that an Xbase++ program would eventually rule the world, until now. :naughty:

Do you have enough information now to continue with this or do you need a special function?
What do you want the function to return?
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to know the attributes of a pixel in the image

#12 Post by Eugene Lutsenko »

If I owned at least 1% of your knowledge ... While I can not verify what you have to offer. But it is in my plans. Be sure to try to understand. Thank you so much. And I'm sure it will be useful not only to me. These functions should be included in the basic features of graphics programming language. I am very grateful for the comprehensive and effective support.

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

Re: How to know the attributes of a pixel in the image

#13 Post by rdonnay »

These functions should be included in the basic features of graphics programming language.
Xbase++ is not a graphics programming language. It is a business language.

It does have some nice graphic features built in, but probably not enough for your needs.
There are several ActiveX and DLL libraries that will work with Xbase++ to give you the power you may need.

The best is Lead Tools. https://www.leadtools.com/

This may be more than you need. Also, it is a bit pricy - $795.00.
You would only need the imaging library.

I used LeadTools many years ago on a project. I forgot what it was for but I remember how powerful and fast it was.
It is just a library, like any other addon library for Xbase++.

Here is an updated program for you that shows how an image can be captured to an array and then the array can be either analyzed or used to paint other image.

Click on "Load Array". It will copy the 224 x 224 pixels into a 2-dimensional array.
Next, click on "Transfer Image", "Flip Image", "Rotate Image".
You will see how you can use this array data.

Code: Select all

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

STATIC snHdll

FUNCTION Main()

LOCAL GetList[0], GetOptions, oSay, hDC1, hDC2, oStatic1, oStatic2, ;
      aPixel[224,224]

@ 0,0 DCSTATIC TYPE XBPSTATIC_TYPE_BITMAP ;
      CAPTION "colors.jpg" ;
      OBJECT oStatic1 ;
      PREEVAL {|o|o:autoSize := .t.} ;
      EVAL {|o|hDC1 := GetWindowDC(o:getHWnd()), ;
               o:motion := {|a,b,o|ShowColor( hDC1, a, oSay, o )}}

@ 0,250 DCSTATIC TYPE XBPSTATIC_TYPE_BITMAP;
      CAPTION "colors.jpg" ;
      PREEVAL {|o|o:autoSize := .t.} ;
      OBJECT oStatic2 ;
      EVAL {|o|hDC2 := GetWindowDC(o:getHWnd())}

@ 50,0 DCSAY '' SAYSIZE 350,20 FONT '10.Lucida Console' OBJECT oSay

@ 100,0 DCPUSHBUTTON CAPTION 'Clear Image' SIZE 100,20 ACTION {||ClearImage(hDC2)}

@ DCGUI_ROW, DCGUI_COL + 20 DCPUSHBUTTON CAPTION 'Transfer Image' ;
    SIZE 80,20 ACTION {||TransferImage(hDC1,hDC2,aPixel)}

@ DCGUI_ROW, DCGUI_COL + 20 DCPUSHBUTTON CAPTION 'Flip Image' ;
    SIZE 80,20 ACTION {||FlipImage(hDC1,hDC2,aPixel)}

@ DCGUI_ROW, DCGUI_COL + 20 DCPUSHBUTTON CAPTION 'Rotate Image' ;
    SIZE 80,20 ACTION {||RotateImage(hDC1,hDC2,aPixel)}

@ DCGUI_ROW, DCGUI_COL + 20 DCPUSHBUTTON CAPTION 'Load Array' ;
    SIZE 80,20 ACTION {||LoadArray(hDC1,aPixel)}

DCGETOPTIONS PIXEL

DCREAD GUI FIT TITLE 'Pixel Test' OPTIONS GetOptions ;
   EVAL {||ClearImage(hDC2)}

RETURN nil

* ---------

FUNCTION LoadArray( hDC1, aPixel )

LOCAL i,j,oScrn

IF !aPixel[1,1] == nil
  DCMSGBOX 'Array is already loaded!'
  RETURN nil
ENDIF

oScrn := DC_WaitOn()

FOR i := 1 TO 224
  FOR j := 1 TO 224
    aPixel[i,j] := GetPixel(hDC1,i-1,j-1)
  NEXT
NEXT

DC_Impl(oScrn)

RETURN nil

* ---------

FUNCTION ClearImage( hDC2 )

LOCAL i,j
LOCAL nColor := AutomationTranslateColor(GraMakeRGBColor({255,255,255}),.f.)

FOR i := 0 TO 224
  FOR j := 0 TO 224
    SetPixel(hDC2,i,j,nColor)
  NEXT
NEXT

RETURN nil

* ----------

FUNCTION TransferImage( hDC1, hDC2, aPixel )

LOCAL i,j, nColor, lEmptyArray := aPixel[1,1] == nil

FOR i := 0 TO 223
  FOR j := 0 TO 223
    IF lEmptyArray
      SetPixel(hDC2,i,j,GetPixel(hDC1,i,j))
    ELSE
      SetPixel(hDC2,i,j,aPixel[i+1,j+1])
    ENDIF
  NEXT
NEXT

RETURN nil

* ----------

FUNCTION FlipImage( hDC1, hDC2, aPixel )

LOCAL i,j, lEmptyArray := aPixel[1,1] == nil

FOR i := 0 TO 223
  FOR j := 0 TO 223
    IF lEmptyArray
      SetPixel(hDC2,j,i,GetPixel(hDC1,j,224-i))
    ELSE
      SetPixel(hDC2,j,i,aPixel[i+1,j+1])
    ENDIF
  NEXT
NEXT

RETURN nil

* ----------

FUNCTION RotateImage( hDC1, hDC2, aPixel )

LOCAL i,j, lEmptyArray := aPixel[1,1] == nil

FOR i := 0 TO 223
  FOR j := 0 TO 223
    IF lEmptyArray
      SetPixel(hDC2,i,j,GetPixel(hDC1,j,224-i))
    ELSE
      SetPixel(hDC2,i,j,aPixel[j+1,224-i])
    ENDIF
  NEXT
NEXT

RETURN nil

* ---------

PROC appsys ; RETURN

* ---------

STATIC FUNCTION ShowColor( hDC, aCoords, oSay, oStatic )

LOCAL nColor

aCoords[2] := oStatic:currentSize()[2] - aCoords[2]

nColor := GetPixel(hDC,aCoords[1],aCoords[2])

oSay:setCaption('Color: ' + DC_Array2String(GraGetRGBIntensity(AutomationTranslateColor(nColor,.T.))) + ;
   ' Coords: ' + DC_Array2String(aCoords))

RETURN nil

#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
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to know the attributes of a pixel in the image

#14 Post by Eugene Lutsenko »

Thank you so much! I will study. When I started working on CLIPPER-87 in 1988 but him on the PC nothing was standing. Pascal was then in its infancy. All other programming languages is an interpreter and can not create software products. So CLIPPER that was all that we have and it did everything we needed.

PS
From 1981 to 1983 I worked on PDP-11 assembly language (under UNIX), 1983 to 1988 on Wang-2200C, and then everything relocate to CLIPPER. And in 2012 began to use Alaska and eXpress++.

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

Re: How to know the attributes of a pixel in the image

#15 Post by rdonnay »

From 1981 to 1983 I worked on PDP-11 assembly language (under UNIX), 1983 to 1988 on Wang-2200C, and then everything relocate to CLIPPER. And in 2012 began to use Alaska and eXpress++.
I started my programming career in about 1979. I wrote assembly language code for computer terminals in 8080 and Z80. From there I went to dBase 2, dBase 3, Clipper and Xbase++. eXpress++ is now 15 years old.
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: How to know the attributes of a pixel in the image

#16 Post by Eugene Lutsenko »

rdonnay wrote:
From 1981 to 1983 I worked on PDP-11 assembly language (under UNIX), 1983 to 1988 on Wang-2200C, and then everything relocate to CLIPPER. And in 2012 began to use Alaska and eXpress++.
I started my programming career in about 1979. I wrote assembly language code for computer terminals in 8080 and Z80. From there I went to dBase 2, dBase 3, Clipper and Xbase++. eXpress++ is now 15 years old.
Yes, there is something to remember and something to say, there were many achievements of its time ... I have a master's thesis was to calculations on computers (1977), and then I worked all my life to computers and programmed. And now I continue programming. By the way, I have the technical sciences doctoral degree in management information systems, and in economic - mathematical modeling and software for the economy (business) and I federal professor in computer technologies. I have a bunch of acts introducing my development with economic effect of about 5 million dollars. For his work, which I spent, chiefs gave the order.

Using the occasion once again, let me thank you for the eXpress++. This is what was needed for all developers in Alaska around the world. I'm sure everyone will agree with me.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to know the attributes of a pixel in the image

#17 Post by skiman »

Hi,

If you are looking for a free solution, maybe you need to check http://freeimage.sourceforge.net/index.html.

There is a wrapper available for it, so you can use it with Xbase++. I think it was posted on the webboard by Hector.
Best regards,

Chris.
www.aboservice.be

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to know the attributes of a pixel in the image

#18 Post by skiman »

Hi,

It looks as the freeimage wrapper isn't on the webboard.

I uploaded a ZIP with everything: DLL, sample prg and documentation. There is a section 'Pixel access functions' in the manual.

http://www.abowebhosting.be/download/freeimage.zip
Best regards,

Chris.
www.aboservice.be


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

Re: How to know the attributes of a pixel in the image

#20 Post by rdonnay »

I corrected the code in previous posting.

RotateImage() was incorrect. Should be this:

Code: Select all

FUNCTION RotateImage( hDC1, hDC2, aPixel )

LOCAL i,j, lEmptyArray := aPixel[1,1] == nil

FOR i := 0 TO 223
  FOR j := 0 TO 223
    IF lEmptyArray
      SetPixel(hDC2,i,j,GetPixel(hDC1,j,224-i))
    ELSE
      SetPixel(hDC2,i,j,aPixel[j+1,224-i])
    ENDIF
  NEXT
NEXT

RETURN nil
The eXpress train is coming - and it has more cars.

Post Reply