Sign in to follow this  
Followers 0
ValeryVal

AZoom

9 posts in this topic

#1 ·  Posted (edited)

This one is image magnifier - AMag.au3

Code of AMag.au3:

#include <GDIPlus.au3>
#include <GuiConstants.au3>
Global $hWnd, $hImage, $hGraphic
Global $ImageWidth, $ImageHeight
Global $GuiWidth = 100, $GuiHeight = 100
Global $ZoomWidth = 400, $ZoomHeight = 400
Global $Scale = 20; 1:10


;Create GUI with Image source
$hWnd = GUICreate("Show PNG", $GuiWidth, $GuiHeight, 0, 0, $WS_THICKFRAME + $WS_POPUP, $WS_EX_TOPMOST)

;Create Zoom GUI
$hWndZ = GUICreate("AZoom", $ZoomWidth, $ZoomHeight, 0, 0, BitOr($WS_THICKFRAME,$WS_POPUP,$WS_SIZEBOX))
$Size = WinGetClientSize ($hWndZ)
$ZoomWidth = $Size[0]
$ZoomHeight = $Size[1]

; Load PNG image
_GDIPlus_StartUp()

GUISetState(@SW_SHOW, $hWnd)
GUISetState(@SW_SHOW, $hWndZ)

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\logo4.gif")

$ImageWidth = _GDIPlus_ImageGetWidth($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight($hImage)

$ImageWidth = _GDIPlus_ImageGetWidth($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight($hImage)

$GuiWidth = $ImageWidth
$GuiHeight = $ImageHeight

WinMove ($hWnd, '', 0, 0, $GuiWidth, $GuiHeight)
WinMove ($hWndZ, '', 0, 0, $ZoomWidth, $ZoomHeight)

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $ImageWidth, $ImageHeight, 0,0, $ImageWidth, $ImageHeight)

; Draw ZoomPNG image
$hGraphicZ = _GDIPlus_GraphicsCreateFromHWND($hWndZ)
_GDIPlus_GraphicsDrawImageRectRect($hGraphicZ, $hImage, 0, 0, 2*$ZoomWidth/$Scale, 2*$ZoomHeight/$Scale, 0,0, $ZoomWidth, $ZoomHeight)

; Loop until user exits
while 1
    $msg = GUIGetMsg(1)
    If $msg[0] = $GUI_EVENT_PRIMARYDOWN Then
    $x = Int($ImageWidth*$msg[3]/$GuiWidth)
    $y = Int($ImageHeight*$msg[4]/$GuiHeight)
    $Size = WinGetClientSize ($hWndZ)
      if $ZoomWidth <> $Size[0] or $ZoomHeight <> $Size[1] then 
      $ZoomWidth = $Size[0]
      $ZoomHeight = $Size[1]
      _GDIPlus_GraphicsDispose($hGraphicZ)
        $hGraphicZ = _GDIPlus_GraphicsCreateFromHWND($hWndZ)
    endif
    $mX = $ZoomWidth/$Scale
    $mY = $ZoomHeight/$Scale
    _GDIPlus_GraphicsClear($hGraphicZ)
      _GDIPlus_GraphicsDrawImageRectRect($hGraphicZ, $hImage, $x-$mX, $y-$mY, 2*$mX, 2*$mY, 0,0, $ZoomWidth, $ZoomHeight)
    endif
    If $msg[0] = $GUI_EVENT_CLOSE Then ExitLoop
wend

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGraphicZ)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

Script uses this file logo4.gif. Must be in script directory.

How to use. You can click original picture to view it's zoom view.

There is a variable $Scale. It is equal here to 20. So scale is equal to 10.

You can resize zoom widow to view more space of source image, too.

Edited by Valery

The point of world view

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

New version of AMag.

File AMag.au3:

#include <GDIPlus.au3>
#include <GuiConstants.au3>
Global $hWnd, $hWndZ
Global $hImage, $hGraphic, $hGraphicZ
Global $ImageWidth, $ImageHeight
Global $GuiWidth = 200, $GuiHeight = 200
Global $ZoomWidth = 400, $ZoomHeight = 400
Global $CurrentX, $CurrentY
Global $Scale = 8; 1:10
Global $hPen

HotKeySet("{Down}", "MoveDown")
HotKeySet("{Up}", "MoveUp")
HotKeySet("{Left}", "MoveLeft")
HotKeySet("{Right}", "MoveRight")

;Create GUI with Image source
$hWnd = GUICreate("Show PNG", $GuiWidth, $GuiHeight, 0, 0, $WS_THICKFRAME + $WS_POPUP, $WS_EX_TOPMOST)

;Create Zoom GUI
$hWndZ = GUICreate("AZoom", $ZoomWidth, $ZoomHeight, 0, 0, BitOr($WS_THICKFRAME,$WS_POPUP,$WS_SIZEBOX))
$Size = WinGetClientSize ($hWndZ)

$ZoomWidth = $Size[0]
$ZoomHeight = $Size[1]

; Load PNG image
_GDIPlus_StartUp()

GUISetState(@SW_SHOW, $hWnd)
GUISetState(@SW_SHOW, $hWndZ)

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\MyPic.jpg")

$ImageWidth = _GDIPlus_ImageGetWidth($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight($hImage)

if $GuiWidth > $ImageWidth and $GuiHeight > $ImageHeight then 
 $GuiWidth = $ImageWidth
 $GuiHeight = $ImageHeight
 WinMove ($hWnd, '', 0, 0, $GuiWidth, $GuiHeight)
 WinMove ($hWndZ, '', 0, 0, $ZoomWidth, $ZoomHeight)
endif

; Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $ImageWidth, $ImageHeight, 0,0, $GuiWidth, $GuiHeight)
$hPen = _GDIPlus_PenCreate(0xFFAAAAAA, 2, 2)

; Draw ZoomPNG image
$hGraphicZ = _GDIPlus_GraphicsCreateFromHWND($hWndZ)
_GDIPlus_GraphicsDrawImageRectRect($hGraphicZ, $hImage, 0, 0, 2*$ZoomWidth/$Scale, 2*$ZoomHeight/$Scale, 0,0, $ZoomWidth, $ZoomHeight)

; Loop until user exits
while 1
 $msg = GUIGetMsg(1)
 Select 
  case $msg[0] = $GUI_EVENT_PRIMARYDOWN
          $CurrentX = $msg[3]
          $CurrentY = $msg[4]
     ChangePosition()
  case $msg[0] = $GUI_EVENT_CLOSE
    ExitLoop
 endselect
wend

; Clean up resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hGraphicZ)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

;=============================
func ChangePosition()

 $Size = WinGetClientSize ($hWnd)
 if $GuiWidth <> $Size[0] or $GuiHeight <> $Size[1] then 
  $GuiWidth = $Size[0]
  $GuiHeight = $Size[1]
  _GDIPlus_GraphicsDispose($hGraphic)
  $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWndZ)
  _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $ImageWidth, $ImageHeight, 0,0, $GuiWidth, $GuiHeight)
 endif

 $x = Int($ImageWidth*$CurrentX/$GuiWidth)
 $y = Int($ImageHeight*$CurrentY/$GuiHeight)

 $Size = WinGetClientSize ($hWndZ)
 if $ZoomWidth <> $Size[0] or $ZoomHeight <> $Size[1] then 
  $ZoomWidth = $Size[0]
  $ZoomHeight = $Size[1]
  _GDIPlus_GraphicsDispose($hGraphicZ)
   $hGraphicZ = _GDIPlus_GraphicsCreateFromHWND($hWndZ)
 endif

 $nX = Int($GuiWidth/$Scale/2)
 $nY = Int($GuiHeight/$Scale/2)
 _GDIPlus_GraphicsClear($hGraphic)
 _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, $ImageWidth, $ImageHeight, 0,0, $GuiWidth, $GuiHeight)
 _GDIPlus_GraphicsDrawRect($hGraphic, $CurrentX-$nX, $CurrentY-$nY, 2*$nX, 2*$nY, $hPen)

 $mX = $ZoomWidth/$Scale
 $mY = $ZoomHeight/$Scale
 _GDIPlus_GraphicsClear($hGraphicZ)
 _GDIPlus_GraphicsDrawImageRectRect($hGraphicZ, $hImage, $x-$mX, $y-$mY, 2*$mX, 2*$mY, 0,0, $ZoomWidth, $ZoomHeight)
endfunc

func MoveDown()
 $CurrentY += 2
 ChangePosition()
endfunc

func MoveUp()
 $CurrentY -= 2
 ChangePosition()
endfunc

func MoveLeft()
 $CurrentX -= 2
 ChangePosition()
endfunc

func MoveRight()
 $CurrentX += 2
 ChangePosition()
endfunc

After click it shows target rectangle and can move it by {Up}, {Down}, {Left}, {Right}

You can use this picture

post-9395-1198161743_thumb.jpg

or other interesting picture instead of.

Edited by Valery

The point of world view

Share this post


Link to post
Share on other sites

Also my zoom program was called AZoom!

Renamed as AMag.au3:

Save aspect ratio and move mouse pointer (without rectangle).


The point of world view

Share this post


Link to post
Share on other sites

I can't get it to work. The box just stays black. WinXP Sp2 here.

Did you download the pics she posted?

Share this post


Link to post
Share on other sites

Did you download the pics she posted?

You have to write "he posted"!


The point of world view

Share this post


Link to post
Share on other sites

Oh, sorry man!

Share this post


Link to post
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
Sign in to follow this  
Followers 0