Image Padder
BlitzMax Forums/BlitzMax Programming/Image Padder
| ||
I could'nt find a program which would open up a sprite sheet, pad the frames and then resave the image - so I coded one:' Image Padder SuperStrict ' the number of pixels you want around your image (ie the border) Const PADDING:Int = 4 ' the width and height of the each frame Const WIDTH:Int = 110 Const HEIGHT:Int = 160 ' number of frames in the file Const FRAMES:Int = 4 Local filter$="Image Files:png; All Files:*" Local testfile$ = RequestFile("Select File...", filter, False, CurrentDir()); If testfile = "" Then Notify "No source Image selected... ", True RuntimeError "No source Image selected... " Else Print "Loading.... "+testfile Local image:TImage = LoadAnimImage(testfile, WIDTH, HEIGHT, 0, FRAMES) Local piximage:TPixmap = LoadPixmap(testfile) If image = Null Print "Error loading image..."+testfile Else Print "Processing..." Local array%[WIDTH, HEIGHT] Local currentFrame% = 0 Local tmp:TPixmap=CreatePixmap:TPixmap(WIDTH*FRAMES + (PADDING*2*FRAMES), HEIGHT + (PADDING*2), PixmapFormat(piximage)) While currentFrame < FRAMES Print "Processing Frame = "+currentFrame Local tmpImage:TPixmap = LockImage(image, currentFrame) ' store the pixels into an array For Local x% = 0 To WIDTH - 1 For Local y% = 0 To HEIGHT -1 Local argb:Int=ReadPixel(tmpImage, x, y) array[x, y] = argb Next Next ' write the pixel Local argb% Local startX% = currentFrame * (WIDTH + (PADDING*2)) Local startY% = 0 For Local x% = startX To WIDTH + (PADDING * 2) + startX - 1 For Local y% = startY To HEIGHT + (PADDING * 2) + startY - 1 argb = $000000 If x >= startX + PADDING And x < startX + WIDTH + PADDING And y >= startY + PADDING And y < startY + HEIGHT + PADDING argb = array[x - startX - PADDING, y - startY - PADDING] EndIf WritePixel(tmp, x, y, argb) Next Next currentFrame = currentFrame + 1 Wend ' save the image Local file:String = testfile + "_new" Print "Saving.... " + file If file > "" SavePixmapPNG(tmp, file, 9) EndIf EndIf Print "" Print "Finished..." End Of course this could be a lot better with a GUI, but meh ;) |
| ||
Oh go on.....make the GUI :D |
| ||
I am working between the days, but I can do a little one tomorrow after work. |
| ||
Ok, here is a first version: There are two different ways to work. Either load an image and do your settings and hit create, or drop a file onto the window and get a new image create without any extra clicks. Of course you can set the padding before. The window is resizable and will show the loaded image and if you manipulate any value it will show the output, but only as pixmap in a panel. I thought that should be enough for such a thing. The values you enter will be checked if they do fit and if not the textfield will turn red to indicate the problematic value. The Statusbar shows some feedback. I have only tried with little strips where the on the fly update of the image is not a problem, if it may is for large images I could add a switch for it. If someone has an icon image I could add it, but I am very bad doing icons... Little Update: A wait cursor is now shown during processing and the padding value is checked as well. Last edited 2011 |
| ||
Very nice jsp! Good job! |
| ||
nice one jsp :) cheers! |
| ||
Thanks guys! Let me know if you need any changes. |