Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SuperStrict
  2.  
  3. Framework maxgui.drivers
  4. Import brl.event
  5. Import brl.eventqueue
  6. Import brl.hook
  7. Import brl.pixmap
  8. Import brl.max2d
  9. Import brl.pngloader
  10. Import brl.tgaloader
  11. Import brl.bmploader
  12. Import brl.jpgloader
  13. Import brl.filesystem
  14.  
  15. Local app:TApp = New TApp
  16. app.run()
  17.  
  18. Type TApp
  19.     Field Window:TGadget
  20.     Field lblDo:TGadget
  21.     Field targetWidth:Int
  22.     Field targetHeight:Int
  23.     Field closeIt:Int
  24.     Method New()
  25.         Self.Window = CreateWindow("Bildresizer - Norwegen Studienfahrt", 0, 0, 400, 150, Null, WINDOW_ACCEPTFILES | WINDOW_CENTER | WINDOW_HIDDEN | WINDOW_TITLEBAR | WINDOW_STATUS)
  26.         Local txt:String = ..
  27.             "Die Bilder zum Resizen einfach auf dieses Fenster ziehen (am besten vorher von den Bildern eine Kopie anfertigen)."
  28.         CreateLabel(txt, 5, 5, Self.Window.ClientWidth() - 10, 40, Self.Window)
  29.         Self.lblDo = CreateLabel("Status: Nichts zu tun.", 5, 45, Self.Window.ClientWidth() - 10, 48, Self.Window)
  30.         Self.Window.SetStatusText("Geschrieben von Lobby Divinus für die Norwegen-Studienfahrt 2011")
  31.         Self.targetWidth = 2400
  32.         Self.targetHeight = 2400
  33.         Self.Window.SetShow(True)
  34.     End Method
  35.     Method run()
  36.         While(Not Self.closeIt And WaitEvent())
  37.             Self.OnEvent(CurrentEvent)
  38.         Wend
  39.     End Method
  40.     Method OnEvent(event:TEvent)
  41.         Select event.id
  42.             Case EVENT_WINDOWCLOSE
  43.                 Self.closeIt = True
  44.             Case EVENT_WINDOWACCEPT
  45.                 Self.addFile(String(event.extra))
  46.         End Select
  47.     End Method
  48.     Method addFile(path:String)
  49.         If FileType(path) = FILETYPE_DIR Then
  50.             Local dir:Int = ReadDir(path)
  51.             Local nFile:String = NextFile(dir)
  52.             While(nFile <> "")
  53.                 If nFile <> "." And nFile <> ".." Then
  54.                     Self.addFile(path + "/" + nFile)
  55.                 End If
  56.                 nFile = NextFile(dir)
  57.             Wend
  58.             CloseDir(dir)
  59.         ElseIf FileType(path) = FILETYPE_FILE Then
  60.             Self.doImage(path)
  61.         End If
  62.     End Method
  63.     Method doImage(path:String)
  64.         Self.lblDo.setText("Status:" + Chr(13) + "Bearbeite: " + path)
  65.         Local pix:TPixmap = LoadPixmap(path)
  66.         If pix Then
  67.             If pix.width >= pix.Height And pix.width > Self.targetWidth Then
  68.                 pix = Self.AdjustPixmap(pix, Self.targetWidth, pix.Height / Float(pix.width) * Self.targetWidth)
  69.                 SavePixmapJPeg(pix, path, 85)
  70.             ElseIf pix.Height > pix.width And pix.Height > Self.targetHeight Then
  71.                 pix = Self.AdjustPixmap(pix, pix.width / Float(pix.Height) * Self.targetHeight, Self.targetHeight)
  72.                 SavePixmapJPeg(pix, path, 85)
  73.             End If
  74.         Else
  75.             Notify("Bild " + path + " konnte nicht verarbeitet werden!")
  76.         End If
  77.         Self.lblDo.setText("Status: Nichts zu tun.")
  78.         PollSystem()
  79.     End Method
  80.     Method AdjustPixmap:TPixmap(pix:TPixmap, w:Int, h:Int)
  81.         pix = ResizePixmap(pix, w, h)
  82.         Return pix
  83.     End Method
  84. End Type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement