Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: tb_graphx

  1. #11
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,138
    Rep Power
    733

    Re: tb_graphx

    Hi Frank,

    on the first place, your module function must not have any parameters:
    [code=thinbasic]
    FUNCTION Exec_GetImageThumbnail (BYVAL hdc AS DWORD) AS EXT
    [/code]
    =>
    [code=thinbasic]
    FUNCTION Exec_GetImageThumbnail () AS EXT
    [/code]
    Everything you need should be parsed in body. Maybe this caused some problems.


    Must goto school, will check it here at night,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  2. #12
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10

    Re: tb_graphx

    Hi Frank,

    I said you the same in my personal message.

    Module function MUST MUST always be defined without any parameters
    Parameters are parsed inside the function using interface functions.
    Also all module functions retuning a number MUST return an EXT number. All conversions will be made by thinBasic.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #13
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    939
    Rep Power
    109

    Re: tb_graphx

    hello petr, eros, thanks for help and hints, I was too fast this morning, overseen this one, my mistake.

    I send my "getImageThumbnail" function as zip file and thinbasic gdiplus example.

    1) I am not sure, if this version is quite correct, but the gpf doesn't appear in gdiplus example anymore with loading background (here: leopards) picture.

    2) for testing purpose I have made a message box for function feedback, the result is "0". but no more gpf's. for console (printl) test it works in my last example too.

    3) would be nice to get feedback by some users, if this added gdiplus example works fine. see my zip file.

    4) if the example doesn't work: the mistake does belongs to this thumbnail function, I am sure now.

    (my thoughts were: but something's still missing. sorry. my idea is: perhaps I have forgotten to add two more functions for "pGraphic" and "pImage" because in powerbasic function these three functions were deleted at the end of script. )

    [code=thinbasic]
    '---> this function works for powerbasic
    '------------------------------------------------------------------


    FUNCTION Exec_GetImageThumbnail () AS EXT
    LOCAL hdc AS DWORD
    LOCAL hStatus AS LONG
    LOCAL pGraphics AS DWORD
    LOCAL strFileName AS STRING
    LOCAL pImage AS DWORD
    LOCAL nWidth AS DWORD
    LOCAL nHeight AS DWORD
    LOCAL pThumbnail AS DWORD
    LOCAL nThumbnailWidth AS DWORD
    LOCAL nThumbnailHeight AS DWORD
    LOCAL pZero AS LONG ' %NULL ?
    LOCAL pZero2 AS LONG ' %NULL ?

    '---Parse open pares
    IF thinBasic_CheckOpenParens() THEN
    thinBasic_ParseLong pImage
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nWidth
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nHeight
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong pThumbnail
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong pZero '?
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong pZero2 '?

    '---At the end check if close parens was specified
    IF thinBasic_CheckCloseParens() THEN

    ' Function = GdipGetImageThumbnail(pImage, 50, 50, pThumbnail, %NULL, %NULL)

    FUNCTION = GdipGetImageThumbnail(pImage, nWidth, nHeight, pThumbnail, 0, 0)

    END IF
    END IF
    END IF
    END IF
    END IF
    END IF
    END IF
    hStatus = GdipCreateFromHDC(hdc, pGraphics)

    ' // Create an image and a thumbnail of the image.
    strFileName = UCODE$("leoparden1.png")
    hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
    hStatus = GdipGetImageThumbnail(pImage, 50, 50, pThumbnail, %NULL, %NULL)

    ' // Draw the original and the thumbnail images.
    hStatus = GdipGetImageWidth(pImage, nWidth)
    hStatus = GdipGetImageHeight(pImage, nHeight)
    hStatus = GdipDrawImageRect(pGraphics, pImage, 70, 70, nWidth, nHeight)

    hStatus = GdipGetImageWidth(pThumbnail, nThumbnailWidth)
    hStatus = GdipGetImageHeight(pThumbnail, nThumbnailHeight)
    hStatus = GdipDrawImageRect(pGraphics, pThumbnail, 200, 20, nThumbnailWidth, nThumbnailHeight)

    ' // Cleanup
    IF pThumbnail THEN GdipDisposeImage(pThumbnail)
    IF pImage THEN GdipDisposeImage(pImage)
    IF pGraphics THEN GdipDeleteGraphics(pGraphics)

    END FUNCTION
    [/code]


    best regards, servus, thanks for looking at the tb script example, Frank
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  4. #14

    Re: tb_graphx

    hello mr. lionheart good morning,

    3) would be nice to get feedback by some users, if this added gdiplus example works fine. see my zip file.
    I can do that: well, have made a copy. yes, your example works well with windows xp2, amd dual processor with no errors, no protection fault.

    your new thumbnail functions will come soon ? I understand you will see what's going on with new module. For testing purpose it's important, I can imagine, that new scripts work at different machines, isn't it?

    there will be a new module called "tb_graphx" like "UI" ? for me it sounds good to have new image manipulations / possibilities (properties) for users. I don't know canvas module. but I will check it too next weeks. - it's easy to create new functions? I think it's very hard stuff, spend a lot of time for it to make new module, I see like michael, petr and eros have done this over weeks, month, years. respectable work I can only say! I am not up to date with all posts here. it's nearly impossible if you are off the road for some days

    bye, have still much to learn with thinbasic (tbgl, ui), I am on a good way. denis

  5. #15
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    939
    Rep Power
    109

    Re: tb_graphx

    hello denis!

    1) thanks for your testing help. don't believe it's not necessary, it's the contrary act! it's very useful. I need this help with feedback, without there is no way to improve new features or functions. It takes only a lot of time to create new things and adept a module to thinbasic. there are limited freedoms for that, you have to oblige to hold serious standards for compiling, I had to learn some month too ("liongfx", created from freebasic to thinbasic), but this was a very, very good exercise and knowledge for me to understand how to parse new functions for thinbasic language interpreter. you can follow this board and can learn a lot, I am sure

    2) It is important, that I've got feedback for my first function, so I can build next issue to fetch an image by my little "tb_graphx" module and can manipulate (here: size) images for new width, height, making thumbnails and some more. it's a good sign, I get an "0" (means: it works ok!) for thumbnail feedback function and not any more error messages or gpf. I can promise you, be patient, there is more to come !

    your new thumbnail functions will come soon ? I understand you will see what's going on with new module. For testing purpose it's important, I can imagine, that new scripts work at different machines, isn't it?
    3) I can say this only for myself, but it's a hard and detailed, continuing working at a new module. I will follow this work with enthusiasm and like to have constructive critics for new suggestions and ideas, I am wide open to hear new things! I have to learn for this module a lot, because there's a lot about gdiplus and other image libraries to learn. without learning some basically aspects of powerbasic programming (e.g. freebasic or any other basic language) it wouldn't be possible to create such a module I think. for me it's an increasing learning process for both sides. I have started programming at all with thinbasic (no joke!) and checked java some month before, but I liked the "easy" and "clear" language of thinbasic and of course the engaged team here with a lot of help.

    4) In general: don't hesitate to ask something isn't clear for you. if you are able to learn something new e.g. at school, you can use it for tbgl or other module show your results here at the forum and ask if you haven't something understand completely. same play belongs to me.

    If there is a new feature or a first good result for a picture manipulation with tb_graphx I will show you here at the new board. wait some days. best and good progress for you with thinbasic learning.

    5) I am little proud that this example caused no more errors

    [code=thinbasic]
    ...
    '-------------------------------------------------------------------
    x = GetImageThumbnail(hGpBitmap,150,150,1,0,0) '--------> frankos test !
    y = GetImageThumbnail(hGpBitmap,150,150,1,0,0)
    '-------------------------------------------------------------------

    MsgBox 0, "All ok here with Thumbnail?: " + GetImageThumbnail(hGpBitmap,150,150,1,0,0),%MB_ICONINFORMATION, "test tb_graphx"
    PrintL GetImageThumbnail(hGpBitmap,150,150,1,0,0)
    ...
    [/code]

    nice evening, best regards, thanks, frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  6. #16
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    939
    Rep Power
    109

    Re: tb_graphx

    hi all.

    I have this little problem how to parse this function correct:

    [code=thinbasic]FUNCTION Exec_DrawImageRect () AS EXT
    LOCAL hdc AS DWORD
    LOCAL hStatus AS LONG
    LOCAL pGraphics AS DWORD
    LOCAL strFileName AS STRING
    LOCAL pImage AS DWORD
    LOCAL nWidth AS DWORD
    LOCAL nWidth1 AS DWORD
    LOCAL nHeight AS DWORD
    LOCAL nHeight1 AS DWORD
    LOCAL pThumbnail AS DWORD
    LOCAL nThumbnailWidth AS DWORD
    LOCAL nThumbnailHeight AS DWORD
    LOCAL pZero AS LONG ' %NULL ?
    LOCAL pZero2 AS LONG ' %NULL ?

    '---Parse open pares
    IF thinBasic_CheckOpenParens() THEN
    thinBasic_ParseLong pImage
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nWidth
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nHeight
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong pThumbnail
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nWidth1
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong nHeight1

    '---At the end check if close parens was specified
    IF thinBasic_CheckCloseParens() THEN

    FUNCTION = GdipDrawImageRect(pGraphics, pImage, nWidth1, nHeight1, nWidth, nHeight)
    'hStatus = GdipDrawImageRect(pGraphics, pImage, 70, 70, nWidth, nHeight)
    END IF
    END IF
    END IF
    END IF
    END IF
    END IF
    END IF

    End Function[/code]

    this is right input for users (if everything is ok):

    "GdipDrawImageRect(pGraphics, pImage, 70, 70, nWidth, nHeight)"

    my problem: what is "70,70" ? this should be a) numbers or b) long ?

    If I compile with powerbasic my GDIplus Example for thinbasic side gives feedback for "0" (all ok), but if I am changing the values for example from thinbasic side

    "pGraphics, pImage, 0, 0, nWidth, nHeight"

    to
    "GdipDrawImageRect(pGraphics, pImage, 20, 20, nWidth, nHeight)"

    then the thinbasic example breaks, if I change values from 0 to 20 or bigger. I think it's not exactly defined what are these numbers.

    2) my thinbasic example is nearly perfect:

    [code=thinbasic] '------------------------------------------------------------------------------
    ' Load needed modules
    '------------------------------------------------------------------------------
    Uses "UI", "console"
    Module "graphx_1xy"

    '------------------------------------------------------------------------------
    ' Equates
    '------------------------------------------------------------------------------
    Begin Const
    %lImage = 1000
    %lImage2
    %lText
    End Const

    Function TBMain()
    '---Test if module was loaded. If not, abort!
    If Uses("GDIP") < 0 Then
    MsgBox 0, "GDI+ lib not found"
    Stop
    End If

    '------------------------------------------------------------------------------
    ' Create dialog
    '------------------------------------------------------------------------------
    Dim hDlg As DWord

    Dialog NEW PIXELS, 0, "thinBasic using GDI+", -1, -1, 400, 326, _
    %WS_DLGFRAME Or _
    %DS_CENTER Or _
    %WS_CAPTION Or _
    %WS_SYSMENU Or _
    %WS_CLIPCHILDREN Or _
    %WS_OVERLAPPEDWINDOW, _
    0 To hDlg

    '------------------------------------------------------------------------------
    ' Show dialog
    '------------------------------------------------------------------------------
    Dialog SHOW MODAL hDlg, Call dlgCallback

    End Function
    '------------------------------------------------------------------------------
    ' Main loop
    '------------------------------------------------------------------------------
    CallBack Function dlgCallback() As Long
    Dim JPGFileName As String = APP_SourcePath + "Images\ferrari-enzo.png"
    Dim JPGFileName2 As String = APP_SourcePath + "Images\leoparden1.png"
    Dim lWidth As Long
    Dim lWidth1 As Long

    Dim lHeight As Long
    Dim lHeight1 As Long
    Dim hBitmap,hBitmap1, hGpBitmap,hGpBitmap1, pImage, pGraphics,pThumbnail As Long
    Dim x,y,z,v,v1 As Long
    Dim nThumbnailWidth, nThumbnailHeight As Long
    nThumbnailWidth = 0
    nThumbnailHeight = 0
    Select Case CBMSG

    Case %WM_INITDIALOG
    '------------------------------------------------------------------------------
    ' Create constrols and Load images
    '------------------------------------------------------------------------------
    Control Add Label, CBHNDL, %lImage,"", 20, 20, 420, 310, %SS_BITMAP

    '---Create an image handle
    hGpBitmap = GDIp_CreateBitMapFromFile(JPGFileName2)

    '---Convert to a BMP handle
    hBitmap = GDIP_HBitMapFromBitmap(hGpBitmap)

    Control SEND CBHNDL, %lImage, %STM_SETIMAGE, %IMAGE_BITMAP, hBitmap
    Control REDRAW CBHNDL, %lImage

    '---Get image W and H
    'lWidth = GDIP_GetImageWidth(hGpBitmap) '--- old
    'lHeight = GDIP_GetImageHeight(hGpBitmap) '--- old

    'lWidth = ImageWidth(hGpBitmap,100)
    'PrintL ImageWidth(hGpBitmap,100)
    'lHeight = ImageHeight(hGpBitmap,100)

    z = DrawImageRect(hGpBitmap,pImage, 0,0,200,200)

    'lWidth1 = GDIP_GetImageWidth(hGpBitmap1) '--- old
    'lHeight1 = GDIP_GetImageHeight(hGpBitmap1) '--- old

    '-> new commands ------------------------------------------------------------------
    lWidth1 = ImageWidth(hGpBitmap1, 100)'nThumbnailWidth
    lHeight1 = ImageHeight(hGpBitmap1,120 )'nThumbnailHeight
    v1 = DrawImageRect(hGpBitmap1, pImage, 0, 0, 400, 400)

    x = GetImageThumbnail(hGpBitmap,150,150,1,0,0) '--------> frankos test !
    y = GetImageThumbnail(hGpBitmap,150,150,1,0,0)

    MsgBox 0, "All ok here with Thumbnail ?: " + GetImageThumbnail(hGpBitmap,150,150,1,0,0),%MB_ICONINFORMATION, "test tb_graphx"
    MsgBox 0, "All ok here with DrawImage ?: " + DrawImageRect(hGpBitmap,pImage, 0,0,100,100),%MB_ICONINFORMATION, "test tb_graphx"
    MsgBox 0, "all ok with ImageRect+pThumbnail ?: " + DrawImageRect(hGpBitmap, pThumbnail, 0, 0, nThumbnailWidth, nThumbnailHeight),%MB_ICONINFORMATION, "test tb_graphx"

    '-> new commands ------------------------------------------------------------------

    PrintL GetImageThumbnail(hGpBitmap,150,150,1,0,0)
    PrintL DrawImageRect(hGpBitmap,pImage,0,0,100,100)
    'PrintL DrawImageRect(hGpBitmap, pThumbnail, 0, 0, nThumbnailWidth, nThumbnailHeight)
    PrintL DrawImageRect(hGpBitmap, pThumbnail, 0, 0, 40, 40)

    Control ADD LABEL, CBHNDL, %lText, "thinBasic GDI+ module wrapper example (" & lWidth & " x " & lHeight & ")", 0, 311, 400, 15, %SS_CENTER
    Control SET COLOR CBHNDL, %lText, RGB(0,0,0), RGB(255,128,0)
    Control REDRAW CBHNDL, %lText

    Control Set Resize CBHNDL, %lImage, 1, 1, 1, 1
    Control SET RESIZE CBHNDL, %lText , 1, 1, 0, 1

    DoEvents

    Case %WM_SIZE
    Control Redraw CBHNDL, %lImage

    Case %WM_CLOSE
    ' -- Erase resources
    '---Release temp hBitmap
    Object_Delete(hBitmap)
    '---Release GDI image
    GDIP_DisposeImage(hGpBitmap)

    End Select

    End Function[/code]

    I add the file plus DLL for testing.

    3) four new commands get positive feedback

    MsgBox 0, "All ok here with Thumbnail ?: " + GetImageThumbnail(hGpBitmap,150,150,1,0,0),%MB_ICONINFORMATION, "test tb_graphx"
    MsgBox 0, "All ok here with DrawImage ?: " + DrawImageRect(hGpBitmap,pImage, 0,0,100,100),%MB_ICONINFORMATION, "test tb_graphx"
    MsgBox 0, "all ok with ImageRect+pThumbnail ?: " + DrawImageRect(hGpBitmap, pThumbnail, 0, 0, nThumbnailWidth, nThumbnailHeight),%MB_ICONINFORMATION, "test tb_graphx"
    lWidth1 = ImageWidth(hGpBitmap1, 100)'nThumbnailWidth
    lHeight1 = ImageHeight(hGpBitmap1,120 )'nThumbnailHeight

    perhaps anybody has a good tip for me.

    best regards, frank
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  7. #17

    Re: tb_graphx

    Hi Franck,

    check the order you parse your parameters. They don't match your command syntax.

    You are parsing right now

    GdipDrawImageRect(pImage, nWidth, nHeight, pThumbnail, nWidth1, nHeight1)

  8. #18
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    939
    Rep Power
    109

    Re: tb_graphx

    thanks michael, I should take a big picture at my wall: "don't work after midnight, if you are tired!" I see, I have copied this function from notebook to desktop pc but haven't cleared the code this early, early morning. my mistake.

    ok, example works. I can change values like I wish.

    now I try to loadImageFromFile and GetImageWidth / GetImageHeight so I am finished

    (hGpBitmap = LoadImageFromFile(StrPtr(strFileName), pImage )

    if I have checked all parameters by parsing I can use my module for first working examples.

    nice evening, thanks for taking attention to my post, Frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  9. #19

    Re: tb_graphx

    Quote Originally Posted by Lionheart008
    thanks michael, I should take a big picture at my wall: "don't work after midnight, if you are tired!"
    Been there, did that too. I think it happens to all of us.

  10. #20
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    939
    Rep Power
    109

    Re: tb_graphx

    hello.

    sorry, but I don't know how to parse this well compiled example from powerbasic side to thinbasic side or how to use this command for thinbasic side:

    powerbasic:
    [code=thinbasic]FUNCTION Exec_LoadImageFromFile() AS EXT
    LOCAL hdc AS DWORD
    LOCAL hStatus AS LONG
    LOCAL pGraphics AS DWORD
    LOCAL strFileName AS STRING
    LOCAL strUFileName AS STRING
    LOCAL pImage AS DWORD


    '---Parse open pares
    IF thinBasic_CheckOpenParens() THEN
    IF thinBasic_CheckOpenParens() THEN
    thinBasic_ParseString strFileName
    IF thinBasic_CheckCloseParens() THEN
    IF thinBasic_CheckComma() THEN
    thinBasic_ParseLong pImage
    IF thinBasic_CheckCloseParens() THEN

    'hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
    FUNCTION = GdipLoadImageFromFile(STRPTR(strFileName), pImage) '--> correct!

    'strUFileName = ucode$(strFileName)
    'GdipLoadImageFromFile(strUFileName, pImage) '--> doesn't work

    END IF
    END IF
    END IF
    END IF
    END IF
    END FUNCTION
    [/code]

    my problem is how to program "STRPTR(strFileName), pImage" correct for thinbasic side using this command:

    thinbasic side (for example):
    [code=thinbasic]
    hGpBitmap = LoadImageFromFile(strFileName, pImage) '--> not ok

    or

    hGpBitmap = LoadImageFromFile(strptr(strFileName), pImage) '--> not ok
    [/code]

    perhaps anybody has experience with this case, would be great. best regards, frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Page 2 of 3 FirstFirst 123 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •