after load Image you can ask Property o:xSize and o:ySize of your Bitmap/Icon.Eugene Lutsenko wrote:By the way, how do you know what the dimension of the image file (in pixels)?
How to know the attributes of a pixel in the image
Re: How to know the attributes of a pixel in the image
greetings by OHR
Jimmy
Jimmy
Re: How to know the attributes of a pixel in the image
The sample code I gave you doesn't really show that what is being loaded is an XbpBitmap() object as the CAPTION.how do you know what the dimension of the image file (in pixels)?
I will modify the code so as to work with any size bitmap.
The eXpress train is coming - and it has more cars.
Re: How to know the attributes of a pixel in the image
Here is the updated code. It will work with images of any size.
Code: Select all
#INCLUDE "dll.CH"
#INCLUDE "dcdialog.CH"
STATIC snHdll
FUNCTION Main()
LOCAL GetList[0], GetOptions, oSay, hDC1, hDC2, oStatic1, oStatic2, ;
aPixel
@ 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 )}, ;
aPixel := Array(o:caption:xSize,o:caption:ySize)}
@ 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,aPixel)}
@ 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,aPixel)}
RETURN nil
* ---------
FUNCTION LoadArray( hDC1, aPixel )
LOCAL i, j, oScrn, nXSize := Len(aPixel), nYSize := Len(aPixel[1])
IF !aPixel[1,1] == nil
DCMSGBOX 'Array is already loaded!'
RETURN nil
ENDIF
oScrn := DC_WaitOn()
FOR i := 1 TO nXSize
FOR j := 1 TO nYSize
aPixel[i,j] := GetPixel(hDC1,i-1,j-1)
NEXT
NEXT
DC_Impl(oScrn)
RETURN nil
* ---------
FUNCTION ClearImage( hDC2, aPixel )
LOCAL i, j, nXSize := Len(aPixel), nYSize := Len(aPixel[1])
LOCAL nColor := AutomationTranslateColor(GraMakeRGBColor({255,255,255}),.f.)
FOR i := 0 TO nXSize
FOR j := 0 TO nYSize
SetPixel(hDC2,i,j,nColor)
NEXT
NEXT
RETURN nil
* ----------
FUNCTION TransferImage( hDC1, hDC2, aPixel )
LOCAL i, j, nColor, lEmptyArray := aPixel[1,1] == nil, ;
nXSize := Len(aPixel), nYSize := Len(aPixel[1])
FOR i := 0 TO nXSize-1
FOR j := 0 TO nYSize-1
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, ;
nXSize := Len(aPixel), nYSize := Len(aPixel[1])
FOR i := 0 TO nXSize-1
FOR j := 0 TO nYSize-1
IF lEmptyArray
SetPixel(hDC2,j,i,GetPixel(hDC1,j,nXSize-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, ;
nXSize := Len(aPixel), nYSize := Len(aPixel[1])
FOR i := 0 TO nXSize-1
FOR j := 0 TO nYSize-1
IF lEmptyArray
SetPixel(hDC2,i,j,GetPixel(hDC1,j,nXSize-i))
ELSE
SetPixel(hDC2,i,j,aPixel[j+1,nXSize-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.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
- 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
Hi, Roger!
I had the opportunity to begin to deal with your interesting programs. I began to modify it to fit your needs. I do not understand everything. Can I ask questions?
The first question is: how to set the size and position of windows to display the original and modified drawings?
I had the opportunity to begin to deal with your interesting programs. I began to modify it to fit your needs. I do not understand everything. Can I ask questions?
The first question is: how to set the size and position of windows to display the original and modified drawings?
Re: How to know the attributes of a pixel in the image
I don't understand your question.The first question is: how to set the size and position of windows to display the original and modified drawings?
Are you saying that you want the 2 images to be in separate windows?
Are you wanting to change the size of the images by changing the size of the windows?
The eXpress train is coming - and it has more cars.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact: