Jump to content

GDI+ Image Cropped during scrolling


Recommended Posts

In the below code, the GDI+ image which is rendered during scrolling gets cropped.

When I scroll up, some lines in the top are cropped but the bottom part is fine. When I scroll down the cropping is in the lower part and the top is fine. Any help with this.

I'm using @Melba23's scroll bar UDF, for the scrollbars

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GUIScrollbars_Ex.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitAll")

_GDIPlus_Startup()

$GraphicCtrl =  GUICtrlCreateGraphic(10, 50, 180, 180)
$Graphics = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($GraphicCtrl))
$Bitmap = _GDIPlus_BitmapCreateFromGraphics(180, 180, $Graphics)
$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)

DrawIcon($Graphics, $Bitmap, $Buffer)
_GUIScrollbars_Generate($hGUI, 0, 400, 0, 0)

GUISetState()

While 1
    Sleep(50)
WEnd

Func DrawIcon(ByRef $hGraphics, ByRef $hBitmap, ByRef $hBuffer)
    _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
    _GDIPlus_GraphicsFillPie($hBuffer, 10, 10, 160, 160, 0, 360)
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")
EndFunc

Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($Graphics, $Bitmap, 0, 0)
EndFunc   ;==>WM_PAINT

Func ExitAll()
    _GDIPlus_GraphicsDispose($Graphics)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_GraphicsDispose($Buffer)

    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>ExitAll

 

Link to comment
Share on other sites

  • Moderators

siva1612,

When I run that code I get no "cropping" - with the scrollbar at the top I see about 80% of the disc and when scrolled down there is a thin slice of the graphic control still visible (I coloured the GUI background to show the graphic control more clearly):

Scroll_1.png

And that is exactly what I would expect with the code as written. Can you please post an image of what you see.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I can see it when I scroll it slowly at the top / bottom of the GUI but it gets refreshed some seconds later.

 

Have a look here:

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@Melba23

I've attached an image of the way it renders for me. I'm using Windows7.

Untitled.png

The image corrects when i activate some other window and come back to it. This is how the above image is supposed to look

Untitled.png

 

UEZ method won't work for me. It uses control move in a child window which will make the scrolling very sluggish, but good to know the trick!!

Edited by siva1612
Link to comment
Share on other sites

  • Moderators

      0 siva1612,

Looks like it is a problem on your machine/graphics card. Sorry I cannot help further.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23 I can reproduce the issue, too.

@siva1612 check out the further examples of that topic, e.g. #9.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Moderators

UEZ,

You always have problems with my UDFs!

What I meant to say was that as I cannot reproduce the problem, I have no idea of how to fix it. Perhaps redrawing the window each time you run the handler will work, but how can I test to see if it does? if someone who experiences the same symptoms wants to play around with the UDF code, then please be my guest.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

InunoTaishou,

I do not doubt that the stated effect is visible to some users - but it is not happening when I scroll the image, so there is nothing I can do to debug why.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Try this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include "GUIScrollbars_Ex.au3"

Opt("GUIOnEventMode", 1)

Const $STM_SETIMAGE = 0x0172
$hGUI = GUICreate("", 220, 200)
$GraphicCtrl =  GUICtrlCreatePic("", 10, 50, 180, 180) ;GUICtrlCreateGraphic(10, 50, 180, 180)
_GUIScrollbars_Generate($hGUI, 0, 400, 0, 0)
GUISetState()

_GDIPlus_Startup()
$Bitmap = _GDIPlus_BitmapCreateFromScan0(180, 180)
$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)
_GDIPlus_GraphicsClear($Buffer, 0xFFFFFFFF)
_GDIPlus_GraphicsFillPie($Buffer, 10, 10, 160, 160, 0, 360)
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap)
_WinAPI_DeleteObject(GUICtrlSendMsg($GraphicCtrl, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))


GUISetOnEvent($GUI_EVENT_CLOSE, "ExitAll")

While 1
    Sleep(50)
WEnd

Func ExitAll()
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_GraphicsDispose($Buffer)
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>ExitAll

 

@Melba23 you see it works with your UDF. ;)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 4 weeks later...

@UEZ Thanks for the workaround. Nice trick to learn. However the below code worked for me.

Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($Graphics, $Bitmap, 0, 0)
    If $wParam = 0 Then _WinAPI_PostMessage($hGUI, $iMsg, 1, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Any idea why this works?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...