forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

saving png as different file name if it exists

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
raptrex



Joined: 29 Sep 2005
Posts: 9

PostPosted: Fri Sep 30, 2005 10:41 am    Post subject: saving png as different file name if it exists Reply with quote

for the base of my "paint" application, im using this script from the tutorial:

Code:
red = Color.new(255, 0, 0);
black = Color.new(0, 0, 0);
white = Color.new(255, 255, 255);

canvas = Image.createEmpty(480, 272)
canvas:clear(white)

brush = {}
eraser = {}

x0 = 0
y0 = 0
x1 = 0
y1 = 0
while true do
   pad = Controls.read()
   dx = pad:analogX()
   if math.abs(dx) > 32 then
      x0 = x0 + dx / 64
   end
   dy = pad:analogY()
   if math.abs(dy) > 32 then
      y0 = y0 + dy / 64
   end
   if pad:cross() then
      canvas:drawLine(x0, y0, x1, y1, black)
   end
   x1 = x0
   y1 = y0
   screen:blit(0, 0, canvas, 0, 0, canvas:width(), canvas:height(), false)
   screen:drawLine(x1 - 5, y1, x1 + 5, y1, red)
   screen:drawLine(x1, y1 - 5, x1, y1 + 5, red)
   screen.waitVblankStart()
   screen.flip()
   if pad:start() then break end
   if pad:select() then screen:save("screenshot.png") end
end


with the use of png instead of tga

how would i do this?:

if screenshot.png exists, save image as screenshot1.png
if screenshot1.png exists, save image as screenshot2.png
ect ect ect

maybe to infinity and beyond
or 10 for now
Back to top
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri Sep 30, 2005 6:33 pm    Post subject: Reply with quote

Code:

function ScreenShot()
    name='screenshot_'
    counter=0
    extension='.png'
    while io.open(name..counter..extension, "r") do
        counter=counter+1
        io.close()
    end
    --reached a filename that does not exist.
    screen:save(name..counter..extension)
end

this code is untested, but i guess it should work.
plz post if it really works and if not, what happens (or report the fix)

greets
lumo
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
raptrex



Joined: 29 Sep 2005
Posts: 9

PostPosted: Fri Sep 30, 2005 10:00 pm    Post subject: Reply with quote

it works perfectly THANK YOU!!!!
your my hero
Back to top
View user's profile Send private message Visit poster's website
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Fri Sep 30, 2005 10:07 pm    Post subject: Reply with quote

fine!
uploaded the lua-file to my webpage :)

greets
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
paulieweb



Joined: 03 Nov 2005
Posts: 8
Location: PSU

PostPosted: Thu Nov 03, 2005 12:31 pm    Post subject: Reply with quote

i tried both raptrex's original screenshot code from the tutorial and lumo's screenshot function, and neither saves a screenshot anywhere on my stick. when i hit the button, the memory stick light flashes like it's saving, but i can't find it. anybody else with this problem?
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
chaos



Joined: 10 Apr 2005
Posts: 135

PostPosted: Thu Nov 03, 2005 1:09 pm    Post subject: Reply with quote

paulieweb wrote:
i tried both raptrex's original screenshot code from the tutorial and lumo's screenshot function, and neither saves a screenshot anywhere on my stick. when i hit the button, the memory stick light flashes like it's saving, but i can't find it. anybody else with this problem?


yeah.. don't use usb mode when taking screenshots, they won't show up.. and you can end up corrupting the memory stick, requiring a reformat.
_________________
Chaosmachine Studios: High Quality Homebrew.
Back to top
View user's profile Send private message
paulieweb



Joined: 03 Nov 2005
Posts: 8
Location: PSU

PostPosted: Thu Nov 03, 2005 2:18 pm    Post subject: Reply with quote

whew, thanks a lot
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Master Inuyasha



Joined: 13 Nov 2005
Posts: 13

PostPosted: Sun Nov 13, 2005 3:18 pm    Post subject: Reply with quote

hey, something is wrong, i installed that into my script, and made it so that when you press pad, it takes a screenshot, but it doesnt work. Heres my code:

elseif pad:select() then
function ScreenShot()
name='ms0:/PSP/PHOTO/screenshot_'
counter=0
extension='.png'
while io.open(name..counter..extension, "r") do
counter=counter+1
io.close()
end
--reached a filename that does not exist.
screen:save(name..counter..extension)
end
end

says got nil calling global value
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group