ID:155532
 
I'm trying to grab every icon_state from an icon file and save them as individual png files using fcopy.

I've tried many different ways, one being:

mob/verb/test()
var
icon/i = new
i.Insert(icon('Test.dmi', "Blue"))
fcopy(i, "temp.png")


I've also tried icon/i = new("blah.dmi"), it has to be an actual icon or it throws an error. Still doesn't work, even with new('blah.dmi').

temp.png always result with an alert saying unable to read.

I also tried:

fcopy(icon('Test.dmi', "Blue"), "temp.png")


Which would be the easiest way if it actually worked.

Any help on how to do this would be greatly appreciated.
Interesting. I just helped someone out with something similar a few weeks ago, and the solution that was working then doesn't appear to create valid files anymore.

Here's what used to work:
mob/verb/Create_Colored_Icon(F as icon, C as color)
// Load the icon file
var/icon/I = icon(F)
// Blend it with the given color
I.Blend(C)
// Save the file to the local directory
fcopy(fcopy_rsc(I),"Colored_[F]")


However, now the output file is just a handful of bytes, regardless of the image:
44 44 4d 49 0d 00 00 00 01 00 00 00 00 08 03 00 00 ff ff 42 00

Only bytes 0x00000010 and 0x00000011 appear to change with the file.

I know they've been making a number of fixes related to /icons created without a file, I wonder if something got lost in the mix.
In response to DarkCampainger
I just came up with this:

#define CACHE_LOC "C:/Users/Jonathon/Documents/BYOND/cache"

proc
savePNG(mob/m, icon/i)
for(var/state in icon_states(i))
var/icon/s = new(i, state)
m << browse_rsc(s, "[state].png")
var/f = file("[CACHE_LOC]/[state].png")
fcopy(f, "[state].png")

mob
verb
test()
savePNG(src, 'Icon.dmi')


It's a little h4xy, and you need to run the world in Trusted mode. But it works. Just have to change CACHE_LOC to wherever your cache is at.
In response to Koil
Ooh, clever. I never thought of using the browser's cache.
In response to DarkCampainger
I tried everything I could think of. Everything produced a broken file except what I just posted.
In response to DarkCampainger
I couldn't get your way to work for my thing except it lead me to a workaround which is wacky.

mob/verb/test()
var
icon/i = icon('Test.dmi', "Blue")
for(var/r = 1 to 18)i.DrawBox(rgb(1,1,1),0,0)
fcopy(i, "temp.png")


DrawBox has to be called at least 18 times before the file is readable, not sure if changing the size of the image will effect it.
In response to Koil
I figured out a whacky workaround [link]
In response to Koil
Here is my version:

proc
Zaltron_savePNG(mob/m, icon/i)
for(var/s in icon_states(i))
var
icon/temp = icon(i, s)
for(var/r = 1 to 18)temp.DrawBox(rgb(1,1,1),0,0)
fcopy(temp, "images/[s].png")
world<<"Saved: [s]"

mob/verb/test()
Zaltron_savePNG(src, 'Test.dmi')
In response to DarkCampainger
I feel a bit silly now. I downloaded the latest BYOND fix and it works as it should.
In response to Zaltron
Zaltron wrote:
I feel a bit silly now. I downloaded the latest BYOND fix and it works as it should.

Oh, haha, you're right. Whoops. Guess they snuck one past us :P
In response to DarkCampainger
It wasn't all for nothing, lead me to find a bug with Scale(). I posted it in the Bug Tracker.