Navigationskarte erstellen

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

Veteran66
Posts: 2
Joined: 10 Feb 2019, 03:44

Navigationskarte erstellen

Post by Veteran66 » 04 Aug 2022, 03:31

Hallo zusammen

für eine Flugsimulation möchte ich eine Navigationskarte erstellen (Peilwinkel, Flugwege usw).
Zuerst die Karte selbst, sie soll mit den Pfeiltaten zoom und verschiebbar sein.

Hier habe ich einen Code gefunden der das so macht, dabei verliert meine Karte (PNG) aber sehr an Qualität.

Code: Select all

/*
 *		Arrow keys move image
 *		Shift + Arrow Up Zooms in
 *		Shift + Arrow Down Zooms out
 */
 
IfNotExist , %A_ScriptDir%\earth-img.jpg  
	URLDownloadToFile , http://upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/1023px-The_Earth_seen_from_Apollo_17.jpg , earth-img.jpg
 
;Settings
	vert	:= 305	;	vertical start position of img in gui
	lat		:= 566	;	lateral start postition of img in gui
	dist 	:= 8  	; 	number of pixels per movement. Bigger numbers = faster movement.
	size	:= 1023	;	Used as initial width and height of img (which is square)
 
;GUI
	Gui , Color	, 000000
	Gui , Add	, Picture , w%size% h-1 x%lat% y%vert%, earth-img.jpg 
	Gui , Show	, w1375 h850 , Move the Earth
	size := 240  ;  Opens full res then resized to 240 by RedrawImage. If opened at 240 image would be pixelated when zoomed.
 
RedrawImage:
	GuiControl, MoveDraw , Static1 , x%lat% y%vert% w%size% h%size%
	Exit
 
GuiClose:
GuiEscape:
	ExitApp
	
;HotKeys	
	Up::
		vert-=dist  ;  shorthand for "vert := vert - dist"
		goto RedrawImage
 
	Down::
		vert+=dist
		goto RedrawImage
 
	Left::
		lat-=dist
		goto RedrawImage
 
	Right::
		lat+=dist
		goto RedrawImage
		
	+Up::  ;  zoom in
		size+=(dist*2)
		vert-=dist
		lat-=dist
		goto RedrawImage
		
	+Down::  ;  zoom out
		size-=(dist*2)
		vert+=dist
		lat+=dist
		goto RedrawImage
Link:
https://www.autohotkey.com/board/topic/98154-moving-an-image-with-arrow-keys/

wie bekomme ich eine bleibende Qualität der Karte?

Gruß Olaf

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Navigationskarte erstellen

Post by BoBo » 04 Aug 2022, 15:52

wie bekomme ich eine bleibende Qualität der Karte?
Ich denke mal, wenn du das Originalformat beibehälst. Wenn jedoch (wie ich hier stark vermute anschließend) herumskaliert wird, wird gelitten.
IMHO wäre für dich die ultimative Lösung SVG-als Ausgangsformat (sofern verfügbar), was AFAIK für verlustfreie Skalierung ausgelegt ist. :think:
Good luck.

BTW, AFAICS offeriert hier @A_AhkUser alternativ die Einbettung eines SVG einer GUI: viewtopic.php?p=348152#p348152 :?: :!:

just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Navigationskarte erstellen

Post by just me » 06 Aug 2022, 03:21

Moin,

sobald Du das Bild für die Anzeige in einem Pic-Element einmal herunterskaliert hast, sind die Feinheiten der Originalgröße unwiederbringlich verloren. Zumindest, wenn es wieder hochskaliert werden soll, solltest Du das Bild in der passenden Größe neu laden:

Code: Select all

#NoEnv
SetBatchLines, -1
/*
 *		Arrow keys move image
 *		Shift + Arrow Up Zooms in
 *		Shift + Arrow Down Zooms out
*/

IfNotExist , %A_ScriptDir%\earth-img.jpg
	URLDownloadToFile, http://upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/1023px-The_Earth_seen_from_Apollo_17.jpg , earth-img.jpg

;Settings
GuiW := 1375 ; GUI width
GuiH := 850  ; GUI height
Dist := 8  	 ; Number of pixels per movement. Bigger numbers = faster movement.
Size := 240	 ; Used as initial width of img (which is square)
MinW := Size ; Minimal width of the image

;GUI
HPIC := LoadPicture("earth-img.jpg", "GDI+ w" . Size . " h-1")
PicGetSize(HPIC, W, H)
Lat  := (GuiW - W) // 2	;	lateral start postition of img in gui
Vert := (GuiH - H) // 2	;	vertical start position of img in gui
Gui, Color, 000000
Gui, Margin, 0, 0
Gui, Add, Picture, vEarth x%Lat% y%Vert%, HBITMAP:%HPIC%
Gui, Show, w%GuiW% h%GuiH%, Move the Earth
Return

ZoomImage:
   HPIC := LoadPicture("earth-img.jpg", "GDI+ w" . Size . " h-1")
   PicGetSize(HPIC, W, H)
   GuiControl, Move, Earth , x%Lat% y%Vert% w%W% h%H%
   GuiControl, , Earth, HBITMAP:%HPIC%
Return

MoveImage:
   GuiControl, Move, Earth , x%Lat% y%Vert%
Return

GuiClose:
GuiEscape:
ExitApp

PicGetSize(HPIC, ByRef W, ByRef H) {
   Static SizeBM := 16 + (A_PtrSize * 2)
   W := H := 0
   VarSetCapacity(BM, SizeBM, 0)
   If DllCall("GetObject", "Ptr", HPIC, "Int", SizeBM, "Ptr", &BM, "Int") {
      W := NumGet(BM, 4, "Int")
      H := NumGet(BM, 8, "Int")
      Return True
   }
   Return False
}

;HotKeys
Up::
	Vert -= Dist  ;  shorthand for "Vert := Vert - Dist"
	Gosub MoveImage
Return

Down::
	Vert += Dist
	Gosub MoveImage
Return

Left::
	Lat -= Dist
	Gosub MoveImage
Return

Right::
	Lat += Dist
	Gosub MoveImage
Return

+Up::  ;  zoom in
	Size += Dist * 2
	Vert -= Dist
	Lat -= Dist
	Gosub ZoomImage
Return

+Down::  ;  zoom out
	Size -= Dist * 2
	Vert += Dist
	Lat += Dist
	Gosub ZoomImage
Return

Post Reply

Return to “Ich brauche Hilfe”