Jump to content




[Solved] Load a paint image from a string


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

#1 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 10 July 2015 - 06:39 PM

How do you LOAD a paint utils image from a string?


--# If this was a standalone file, it would work, but I only want to use a single file.
local image = [[	   fffffff
	   f44444f
	   f44444f
	   f44444f
	   fffffff
fffffffffffffffffffff
f44444fffffffff44444f
f44444fffffffff44444f
f44444fffffffff44444f
8888888fffffff8888888
	   ffffffffffffff
	   f44444ff44444f
	   f44444ff44444f
	   f44444ff44444f
	   fffffff8888888]]

paintutils.loadImage( ? )

'paintutils.loadImage' only accepts a file path, not a string.

Would the easiest way be temporarily saving the string to file to let paintutils read it?
( Note that I don't want to save the table that is created, I prefer to saving the string. For reasons )

Edited by HPWebcamAble, 10 July 2015 - 07:14 PM.


#2 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 10 July 2015 - 06:46 PM

Is there a particular reason you wish to load from a string? I only ask to determine what solutions may be worth your time.

#3 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 10 July 2015 - 06:55 PM

View PostTYKUHN2, on 10 July 2015 - 06:46 PM, said:

Is there a particular reason you wish to load from a string? I only ask to determine what solutions may be worth your time.

Well I want to display it in a program, but without having more than 1 file.


While I was waiting for a reply, I just had my program save the string to a temporary file, load the image, then delete the file.
It works, but I'm still wondering if there is a better way.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 July 2015 - 06:56 PM

Look at the paintutils API and rework the loading function to create a new version for your program that loads from a string.

#5 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 10 July 2015 - 07:01 PM

You could convert the string into the numerical forms and put it into a table with the paintutils format.

As far as I know paintutils just makes a table and thats all. So for that last line of your string the value would be

{0, 0, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 256, 256, 256, 256, 256, 256, 256}

Again not sure if it is worth the time using this particular solution.

#6 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 10 July 2015 - 07:13 PM

View PostLyqyd, on 10 July 2015 - 06:56 PM, said:

Look at the paintutils API and rework the loading function to create a new version for your program that loads from a string.

Don't know why I didn't think of that :P
It should be really easy.


View PostTYKUHN2, on 10 July 2015 - 07:01 PM, said:

You could convert the string into the numerical forms and put it into a table with the paintutils format.

As far as I know paintutils just makes a table and thats all. So for that last line of your string the value would be

{0, 0, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 256, 256, 256, 256, 256, 256, 256}

Again not sure if it is worth the time using this particular solution.

Well, I didn't want to use the table because when it is first created (using textutils.serialize), it's about 50 lines, so if I ever edited the original, I'd need to manually reformat the outputed table.
Also, the string version is much small without having to do anything to it, plus you can edit it pretty easily.

Edited by HPWebcamAble, 10 July 2015 - 07:13 PM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 10 July 2015 - 11:50 PM

Truth be told, paintutils.drawImage() is a bit slower than it has to be. I somewhat recently wrote a somewhat more efficient renderer, here's a version that'll do what you want:

Spoiler

Edited by Bomb Bloke, 10 July 2015 - 11:53 PM.


#8 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 11 July 2015 - 12:44 AM

View PostBomb Bloke, on 10 July 2015 - 11:50 PM, said:

Truth be told, paintutils.drawImage() is a bit slower than it has to be. I somewhat recently wrote a somewhat more efficient renderer, here's a version that'll do what you want:

I'm not rendering this image more than once when it appears, and it isn't the end of the world if it flickers when drawing. I think paintutils will work for now

Although, I hadn't thought of term.blit, still not used to having it. Which I technically don't, as I use the DW20 1.7.10 pack, which still hasn't updated CC yet.
It would be really easy to draw the image with term.blit though. I actually add text over the image after paintutils draws it, and term.blit could take care of that when drawing the image.

Edited by HPWebcamAble, 11 July 2015 - 12:45 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users