Jump to content




Saving screens as a file


  • You cannot reply to this topic
6 replies to this topic

#1 johnnic

  • Members
  • 50 posts
  • LocationSomewhere in ****** County, *******

Posted 02 July 2013 - 11:15 PM

In my OS, I would like to be able to save different parts of your desktop/whatever and be able to load those later. Is there any way to save what is on a computer in a paint format?

#2 Shnupbups

  • Members
  • 596 posts
  • LocationThat place over there. Y'know. The one where I am.

Posted 03 July 2013 - 01:05 AM

Not directly, but you could write a function to do so.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 July 2013 - 01:40 AM

As Shnupbups said, not directly. However it is completely possible. A possible solution that I can think of requires you to have a screen buffer, i.e. a table that contains information about all the background colours, text colours and the characters on the screen.
Then you can loop through the buffer printing its contents to file. An easy way of writing colours out to a file is like so
local function colorToHex(col)
  --# return an empty string when it isn't a valid colour
  if not col or not tonumber(col) then
	return " "
  end
  --# reduce the colour from the 2^16 scale down to numbers 0-15
  col = math.floor( math.log(col) / math.log(2) )
  --# turn the numbers 0-15 into hexadecimal ( 0-F ... hex is 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f )
  return string.format("%X", col)
end
Then to convert them back
local function hexToColor(hex)
  --# if there is no value, or its not a hex character
  if not hex or not tonumber(hex,16) then
	return colors.black
  end
  --# convert from 0-F to 0-15 ... we use 16 because hex is base-16
  hex = tonumber(hex, 16)
  --# return our color
  return 2^hex
end

Doing the above method creates the same file format as paint and nPaintPro.

#4 johnnic

  • Members
  • 50 posts
  • LocationSomewhere in ****** County, *******

Posted 03 July 2013 - 09:07 AM

How would i make the screen a saveable string in the first place?

#5 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 03 July 2013 - 12:25 PM

Are you trying to make a screenshot program or something?
If so then you would probably need to track everything that has happened on the screen since startup because it'll need to know what has been printed etc. And the best way todo this is a coroutine function that's been run from startup or something and it stores the stuff into a table.. But idk.. Kinda hard to make this..

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 04 July 2013 - 12:12 AM

View Postjohnnic, on 03 July 2013 - 09:07 AM, said:

How would i make the screen a saveable string in the first place?

View PostHellkid98, on 03 July 2013 - 12:25 PM, said:

If so then you would probably need to track everything that has happened on the screen since startup because it'll need to know what has been printed etc.

View Posttheoriginalbit, on 03 July 2013 - 01:40 AM, said:

A possible solution that I can think of requires you to have a screen buffer, i.e. a table that contains information about all the background colours, text colours and the characters on the screen.


#7 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 05 July 2013 - 08:48 AM

Sorry... Didn't read that..





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users