Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SuperStrict
- Framework maxgui.drivers
- Import brl.event
- Import brl.eventqueue
- Import brl.hook
- Import brl.pixmap
- Import brl.max2d
- Import brl.pngloader
- Import brl.tgaloader
- Import brl.bmploader
- Import brl.jpgloader
- Import brl.filesystem
- Local app:TApp = New TApp
- app.run()
- Type TApp
- Field Window:TGadget
- Field lblDo:TGadget
- Field targetWidth:Int
- Field targetHeight:Int
- Field closeIt:Int
- Method New()
- Self.Window = CreateWindow("Bildresizer - Norwegen Studienfahrt", 0, 0, 400, 150, Null, WINDOW_ACCEPTFILES | WINDOW_CENTER | WINDOW_HIDDEN | WINDOW_TITLEBAR | WINDOW_STATUS)
- Local txt:String = ..
- "Die Bilder zum Resizen einfach auf dieses Fenster ziehen (am besten vorher von den Bildern eine Kopie anfertigen)."
- CreateLabel(txt, 5, 5, Self.Window.ClientWidth() - 10, 40, Self.Window)
- Self.lblDo = CreateLabel("Status: Nichts zu tun.", 5, 45, Self.Window.ClientWidth() - 10, 48, Self.Window)
- Self.Window.SetStatusText("Geschrieben von Lobby Divinus für die Norwegen-Studienfahrt 2011")
- Self.targetWidth = 2400
- Self.targetHeight = 2400
- Self.Window.SetShow(True)
- End Method
- Method run()
- While(Not Self.closeIt And WaitEvent())
- Self.OnEvent(CurrentEvent)
- Wend
- End Method
- Method OnEvent(event:TEvent)
- Select event.id
- Case EVENT_WINDOWCLOSE
- Self.closeIt = True
- Case EVENT_WINDOWACCEPT
- Self.addFile(String(event.extra))
- End Select
- End Method
- Method addFile(path:String)
- If FileType(path) = FILETYPE_DIR Then
- Local dir:Int = ReadDir(path)
- Local nFile:String = NextFile(dir)
- While(nFile <> "")
- If nFile <> "." And nFile <> ".." Then
- Self.addFile(path + "/" + nFile)
- End If
- nFile = NextFile(dir)
- Wend
- CloseDir(dir)
- ElseIf FileType(path) = FILETYPE_FILE Then
- Self.doImage(path)
- End If
- End Method
- Method doImage(path:String)
- Self.lblDo.setText("Status:" + Chr(13) + "Bearbeite: " + path)
- Local pix:TPixmap = LoadPixmap(path)
- If pix Then
- If pix.width >= pix.Height And pix.width > Self.targetWidth Then
- pix = Self.AdjustPixmap(pix, Self.targetWidth, pix.Height / Float(pix.width) * Self.targetWidth)
- SavePixmapJPeg(pix, path, 85)
- ElseIf pix.Height > pix.width And pix.Height > Self.targetHeight Then
- pix = Self.AdjustPixmap(pix, pix.width / Float(pix.Height) * Self.targetHeight, Self.targetHeight)
- SavePixmapJPeg(pix, path, 85)
- End If
- Else
- Notify("Bild " + path + " konnte nicht verarbeitet werden!")
- End If
- Self.lblDo.setText("Status: Nichts zu tun.")
- PollSystem()
- End Method
- Method AdjustPixmap:TPixmap(pix:TPixmap, w:Int, h:Int)
- pix = ResizePixmap(pix, w, h)
- Return pix
- End Method
- End Type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement