• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Post your questions here

Started by Patrice Terrier, December 10, 2008, 03:20:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

This thread is to post your questions about GDImage ...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

#1
I've been very pleased with the functionality of GDImage, though I'm having problems with rotating an image that I've loaded from my program's resource file.  Here is the boiled down code that shows where I'm struggling:

#PBFORMS CREATED
'SED_PBWIN
#COMPILE EXE
#DIM ALL

#PBFORMS BEGIN INCLUDES
#RESOURCE "DMV.pbr"
#INCLUDE "DMV.inc"
#PBFORMS END INCLUDES

'--------------------------------------------------------------------------------
'   ** Constants **
'--------------------------------------------------------------------------------
'--------------------------------------------------------------------------------
#PBFORMS BEGIN CONSTANTS
%IDD_DIALOG1      = 101
%IDC_GDimageCTRL1 = 102
%ID_TIMER1        = 103
%ID_BITMAP_ARROW  = 1     ' Bitmap overlay
#PBFORMS END CONSTANTS
'--------------------------------------------------------------------------------

'--------------------------------------------------------------------------------
'   ** Declarations **
'--------------------------------------------------------------------------------
DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
declare sub DisplayArrow(hDlg as long)
#PBFORMS DECLARATIONS
'--------------------------------------------------------------------------------

' Search for "GDImage" in the source code
#INCLUDE "GDImage.inc"   ' GDImage

'$MyImage1 = "level01.jpg" + "<fit>" ' GDImage (edit this using a full path name to image)
$MyImage1 = "" + "<fit>" ' GDImage (edit this using a full path name to image)

global lHor as long, lVer as long, lDep as LONG, lDir as LONG, ghCtrl&

'--------------------------------------------------------------------------------
FUNCTION PBMAIN()
RegisterGDImageClass                ' GDImage
ShowDIALOG1 %HWND_DESKTOP
END FUNCTION 'PBMAIN
'--------------------------------------------------------------------------------

'--------------------------------------------------------------------------------
'   ** CallBacks **
'--------------------------------------------------------------------------------
CALLBACK FUNCTION ShowDIALOG1Proc()
local hBitmapFromResource&

SELECT CASE AS LONG CBMSG
    CASE %WM_INITDIALOG
      STATIC idEvent AS LONG

'Initialization handler
'Load Arrow Bitmap from resource, and create a BITMAP overlay
ghCtrl& = GetDlgItem(cbhndl, %IDC_GDimageCTRL1)
if hBitmapFromResource& = 0 then hBitmapFromResource& = ZI_LoadBitmap("BMP_ARROW") ' Load it ONLY ONCE !
CALL ZD_DrawBitmapToCtrl(ghCtrl&, 174, 0, hBitmapFromResource&, ZD_ColorARGB(255,0), %ID_BITMAP_ARROW, %ZS_VISIBLE)
ZD_SetObjectLocked %ID_BITMAP_ARROW, %TRUE

      'Create WM_TIMER events with the SetTimer API at 500 ms (0.5 s) interval
idEvent = SetTimer(CBHNDL, %ID_TIMER1, 500, BYVAL %NULL)
      DIALOG POST CBHNDL, %WM_TIMER, %ID_TIMER1, 0  ' force an initial %WM_TIMER "event"
CASE %WM_TIMER                                  ' Posted by the created timer
IF CBWPARAM = %ID_TIMER1 THEN               ' Make sure it's corrent timer id
'Do some processing here that's removed
DisplayArrow cbhndl
END IF
    CASE %WM_PALETTECHANGED
      'if in 256 color mode, switching between app's with different palettes
      'can cause weird results. Trapping %WM_PALETTECHANGED and redrawing
      'entire dialog helps some. Maybe not the best solution, but..
      IF CBWPARAM <> CBHNDL THEN
        RedrawWindow CBHNDL, BYVAL 0, BYVAL 0, %RDW_INVALIDATE OR %RDW_UPDATENOW
      END IF
    CASE %WM_DESTROY
    'is sent when program ends - a good place to delete created
    'objects and store settings in file for next run, etc.
    '-------------------------------------------------------------
CASE %WM_NCACTIVATE
STATIC hWndSaveFocus AS DWORD
IF ISFALSE CBWPARAM THEN
' Save control focus
hWndSaveFocus = GetFocus()
ELSEIF hWndSaveFocus THEN
' Restore control focus
SetFocus(hWndSaveFocus)
hWndSaveFocus = 0
END IF
CASE %WM_COMMAND
      ' Process control notifications
      SELECT CASE AS LONG CBCTL
        CASE %IDCANCEL
          IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
DIALOG END CBHNDL, 0
          END IF
      END SELECT
    END SELECT
END FUNCTION 'ShowDIALOG1Proc
'--------------------------------------------------------------------------------

'--------------------------------------------------------------------------------
FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG
#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
LOCAL hDlg  AS DWORD

DIALOG NEW hParent, "Demise Map Viewer", 43, 58, 497, 413, %WS_POPUP OR %WS_BORDER OR _
  %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
  %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
  OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
CONTROL ADD $GDImageClassName, hDlg, %IDC_GDimageCTRL1, $MyImage1, 7, 5, 423, 390, %WS_CHILD OR _
  %WS_VISIBLE, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
#PBFORMS END DIALOG

'Example for above as PBForms always jacks it up.
'CONTROL ADD $GDImageClassName, hDlg, %IDC_GDimageCTRL1, $MyImage1, 7, 5, 420, 190

DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION 'ShowDIALOG1
'--------------------------------------------------------------------------------

sub DisplayArrow(hDlg as long)
local lHorP as LONG, lVerP as long

'Layout looks like this:
'1,45   45,45
'1, 1   45, 1

lHor = 24 'Horizontal coordinate
lVer = 3  'Vertical coordinate
lDep = 1  'Which map we're on
lDir = 2  'Direction facing

lHorP = (lHor * 14) - 12
lVerP = ((45 - lVer) * 14) + 2

select CASE lDir
case 1 'North
ZD_SetObjectRotation %ID_BITMAP_ARROW, 0
case 2 'East
CALL ZD_SetObjectAngle(%ID_BITMAP_ARROW, 90, %TRUE)
'ZD_SetObjectRotation %ID_BITMAP_ARROW, 90
'ZD_RotateObjectClockWise90 (%ID_BITMAP_ARROW)
case 3 'South
ZD_SetObjectRotation %ID_BITMAP_ARROW, 180
'ZD_FlipObjectY %ID_BITMAP_ARROW
case 4 'West
'ZD_SetObjectRotation (%ID_BITMAP_ARROW, 270)
END SELECT

ZD_SetObjectXY %ID_BITMAP_ARROW, lHorP, lVerP, 1
CALL ZI_UpdateWindow(ghCtrl&, %TRUE)
END SUB


Here's a zip archive that is compilable but does not include the GDImage.dll file or the includes.  I'm using the demo version available from the ZAP site that is version 4.06 (according to the header file).

<I've pulled the link as it's been replaced>

...in the SUB DisplayArrow I update the placement of an arrow against a map background based on a timer.  When my program is ran, the arrow moves along just fine using the SUB as it is; but, it doesn't face the way that I would like.  I'd like to have it point east when traveling east and so on.  The placement is pulled from a game. In the above SUB I've given sample coordinates to showcase the basics.  I've tried a few things that you can see in the SELECT CASE to no avail.  Any ideas or am I horribly butchering something?

Patrice Terrier

#2
Donnie,

I am not comfortable with the DDT proprietary syntax, however the first thing that comes to my mind is that your arrow PNG file uses an original angle rotation of 90° instead of 0°, and that could explain the problem you have to perform the correct rotation of your arrow.

If you are looking at a clock, then three = 0°, while twelve = 90°, nine = 180°, six = 270°.

Also with PNG file you must always use
CALL ZD_UsePngOpacity(%ID_BITMAP_ARROW, %TRUE)
in order to use alpha channel and zooming capabilities


'Initialization handler
'Load Arrow Bitmap from resource, and create a BITMAP overlay
ghCtrl& = GetDlgItem(cbhndl, %IDC_GDimageCTRL1)
if hBitmapFromResource& = 0 then hBitmapFromResource& = ZI_LoadBitmap("BMP_ARROW") ' Load it ONLY ONCE !
CALL ZD_DrawBitmapToCtrl(ghCtrl&, 174, 0, hBitmapFromResource&, ZD_ColorARGB(255,0), %ID_BITMAP_ARROW, %ZS_VISIBLE)

CALL ZD_UsePngOpacity(%ID_BITMAP_ARROW, %TRUE)
CALL ZD_SetObjectAngle(%ID_BITMAP_ARROW, 180, %TRUE)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

This is perfect.  I was able to incorporate what you showed me and placed it in my code.  It very neatly works now.

Robert Sarrazin

Hi. I try to use the:
I call:
---------------------------
MsgBox "Past #1 "
    Call  ZI_GetImageSizeFromFile ("c:\aFireFly\GDImage\image.jpg", 0, 0 )
    MsgBox "Result #2 = " + Str$(imgWidth)
    Call test()
    ..............

SUB ZI_GetImageSizeFromFile ( _
      zFullPathName As Asciiz, _      ' The name  graphic file size.
      imgWidth As Long, _             ' Width of the picture.
      imgHeight As Long _             ' Height of the picture.
      )
      MsgBox "Past #3 here "
End Sub

'------------------------------
Sub test()
      MsgBox "Past #4 testsub ok "
End Sub
-------------------------------
Result
display Past #1
display Result #2 = 0
display Past #4 testsub ok
-------------------------------
It seem it never go to sub ZI_GetImageSizeFromFile
I never see Past #3 here
I use your trail version
I download today not sure about the way I code.
but my kind of trace help me to figure out I have a problem.
I try to use Firefly 2.91
Thanks.

Patrice Terrier

Robert,

ZI_GetImageSizeFromFile is a GDImage API, thus you are not allowed to duplicate the name of this API in your own code, that is a NoNo.

Also to get the width and height values, you must first declare in your code two numeric parameters like this:
LOCAL imgWidth, imgHeight AS LONG

Then use the API this way:

CALL ZI_GetImageSizeFromFile("c:\aFireFly\GDImage\image.jpg", imgWidth, imgHeight)
MsgBox STR$(imgWidth) + STR$(imgHeight)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Robert Sarrazin

Thanks more clear, now it work well but to came back to
my goal to resize image I find 1 command to seize image.

    Call  ZI_GetImageSizeFromFile ("c:\aFireFly\GDImage\10.jpg", imgWidth, imgHeight )
    imgWidth=imgWidth / 10
    imgHeight=imgHeight / 10
    ZI_FitImageFromFile("c:\aFireFly\GDImage\10.jpg",imgWidth,imgHeight)

But I don't know where the fitImage go in memory? or where?
How to sent this image to hWndForm, I never sent this image to hWndForm.
Now if I want to use the only one else commande to save:

    ZI_SaveBitmapToFile("c:\aFireFly\GDImage\10n.jpg",hWndForm,80)

Easy to see is not working the hWndForm have no instruction.

I read all the function 1 by 1 to find how to resize image that only 2
function I find. Again few for zomming a lot of get but not to many
for set image.

I am right?, It look you convert all image (Jpg, Tif, gif, etc.) to bitmap,
at that point you modify you play with the way you want, and if we
want to save the result; you convert again to save in any format.

1 more question: when I use:
      gnCtrl = CreateWindowEx(ExStyles, _   ' 0
                              ClassName, _  ' "ZIMAGECTRL"
                              Caption, _    ' Full path to default image ""
                              Styles, _     ' %WS_CHILD Or %WS_VISIBLE
                              nLeft, nTop, nWidth, nHeight, _
                              hWndParent, IDC_FORM1_GDIMAGECONTROL, _
                              GetModuleHandle(ByVal %Null), _
                              ByVal %Null)

If I got no picture It came with, BLACK windows, can we change that color
by white or any or transparency.
The color is just the look but the way to use resize or save is all the program.
Thanks again.



Patrice Terrier

#7
Robert,

Please studdy the examples provided with the trial version, then start modifying one of them to achieve your goal.

Usualy the ZI_FitimageFromFile returns a resized bitmap handle that must be assigned to a GDImage graphic control.

But if you want you can save the newly created bitmap directly to disk, using ZI_SaveBitmap.

GDImage is able to handle either GDI bitmap or GDIPLUS bitmap (image).

There is also a low level GDImage API to convert from Bitmap to Image (GDIPLUS), its name is zBitmapToImage.

See the convert.bas example, i think it could help you, and it can't be simpler than that:


#COMPILE EXE "convert.exe"
%WINAPI                                         = 1
%WM_USER                                        = &H400
TYPE POINTS
  x AS INTEGER
  y AS INTEGER
END TYPE

#INCLUDE "gdimage.inc"

FUNCTION PBMAIN
    LOCAL hBitmap AS LONG, ErrorCode AS LONG

    hBitmap = ZI_FitImageFromFile("C:\multimedia\pictures\skins\wallpapers\cogs2.jpg", 48, 48)
    ErrorCode = ZI_SaveBitmapToFile("c:\travail\gdimage\icon.jpg", hBitmap, 0)
    CALL DeleteObject(hBitmap)

END FUNCTION

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Robert Sarrazin

Thanks Patrice
I post the result:
http://www.jose.it-berater.org/smfforum/index.php?topic=2966.msg9040#msg9040

With the help for drag and drop from: Paul Squires
and the project is done. Voila!  8)
I got the drop and drag.
The resize all image and .ext
The preview image for the result.
The detection for not graphics file.
The performance.

Thanks to answer:  "all my questions".
Robert.

Patrice Terrier

Robert,

When saving to JPEG you can select the Quality (using the last parameter of ZI_SaveBitmapToFile).

GDImage's default for JPEG is always the highest quality if you don't specify a value (see the CHM help file).

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Robert,

I forget to say that you must delete the bitmap object when you are done, using:
CALL DeleteObject(hBitmap)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

#11
The example code has been a great boon to me in having some fun with graphics..  I didn't realize that I would have to do so much math though.  I've edited the zoomplus.bas file a bit to show my question.  If you right-click on the black square of Monaco you'll get the coordinates around 301, 209.  If you zoom all the way in, recenter Monaco and click the black square, you'll get 211, 192.  If you maximize the dialog, recenter Monaco I got 543, 476 with my settings.  I understand that I'm getting different coordinates because of the size of the image and the zoom factor; but, is it possible to mathematically get them all to match?  What would I need to do to accomplish that?


Donnie Ewald

Feel free to look at the attachment; but, I think I'm getting closer to solving this.  I'll post a changed attachment if I do.  I will be out of town for a few days so it might be a bit.

Patrice Terrier

#13
Donnie,

GDImage does already the hard work for you.
ZI_GetCropCoordinates API returns real coordinates as if you were viewing without zoom factor (1/1)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Donnie Ewald

#14
I noticed that; but, I'd prefer a mouse-click instead of creating a crop rectangle.  I don't see any other way to use that SUB.  I've got it figured out when the user resizes the dialog or maximizes; but, no luck yet on zooming.  Hopefully I'll get a chance to tackle it when I'm back.