leos Posted April 1, 2009 Share Posted April 1, 2009 (edited) I am working on a GPS utility. I want to show only a part of a map (jpg image file on disk) into a form. My script is working but not as i have expected: #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hForm1, $hBitmap, $hGraphic, $nMsg $hForm1 = GUICreate("Map", 700, 700, 100, 20) GUISetState(@SW_SHOW, $hForm1) _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.jpg"); create a bitmap object from file $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1 _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic While 1 $nMsg=GUIGetMsg() If $nMsg=$GUI_EVENT_CLOSE Then ; Clean up resources _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() Exit EndIf WEnd The problem is that the image shown in the graphic has not the same scale as the original image in the jpg file shown on screen by a graphic utility. Image in the graph is something like 30% bigger than the source image and, because of the magnification, original image looses it's sharpness. What can I do to keep the same image size in both contexts (Autoit GUI and size of the jpg image shown 100% size by usual graphic viewers like Irfanview, Paint..? Edited April 1, 2009 by leos Link to comment Share on other sites More sharing options...
Malkey Posted April 1, 2009 Share Posted April 1, 2009 I am working on a GPS utility. I want to show only a part of a map (jpg image file on disk) into a form. My script is working but not as i have expected: #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hForm1, $hBitmap, $hGraphic, $nMsg $hForm1 = GUICreate("Map", 700, 700, 100, 20) GUISetState(@SW_SHOW, $hForm1) _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.jpg"); create a bitmap object from file $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1 _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic While 1 $nMsg=GUIGetMsg() If $nMsg=$GUI_EVENT_CLOSE Then ; Clean up resources _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() Exit EndIf WEnd The problem is that the image shown in the graphic has not the same scale as the original image in the jpg file shown on screen by a graphic utility. Image in the graph is something like 30% bigger than the source image and, because of the magnification, original image looses it's sharpness. What can I do to keep the same image size in both contexts (Autoit GUI and size of the jpg image shown 100% size by usual graphic viewers like Irfanview, Paint..?I am not sure if this is a solution. It may help. #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $hForm1, $hBitmap, $hGraphic, $nMsg _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.jpg"); create a bitmap object from file $iX = _GDIPlus_ImageGetWidth($hBitmap) $iY = _GDIPlus_ImageGetHeight($hBitmap) ;ConsoleWrite("$iX = " & $iX & " $iY = " & $iY & @CRLF) $hForm1 = GUICreate("Map", $iX, $iY, 100, 20) GUISetState(@SW_SHOW, $hForm1) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1 _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then ; Clean up resources _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() Exit EndIf WEnd Link to comment Share on other sites More sharing options...
leos Posted April 1, 2009 Author Share Posted April 1, 2009 (edited) Thank's, but the problem is now, somehow, similar. Now, both images are identical regarding vertical and horizontal size in pixels but now, the image from the form represents only a part of the image in the file. My problem with gdi+ is that a bitmap image from a file, with horizontal dimension x pixels and vertical size y pixels is NOT represented in a form at same dimensions. Edited later: Problem solved. The bitmap rescaling appeared due to the difference in resolution. JPEG file resolution was 72dpi and screen resolution is 96dpi. In that case, GDI+ functions (_GDIPlus_BitmapCreateFromFile, _GDIPlus_GraphicsDrawImage) automatically scale the image when displaying it in a form. After setting jpeg file resolution at 96dpi, the image of the file shown in form, constructed with GDI+ functions, is identical with the image of the file shown by a graphical utility like Irfanview (at full size) Edited April 1, 2009 by leos Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now