• Welcome to SC4 Devotion Forum Archives.

Simple FSH<>PNG Tools

Started by Jonathan, March 02, 2009, 12:11:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

puresim

Sorry for the delay. I do get that error dialog when I drop the fsh files.



Seems like Reader isn't saving the files properly. Thanks null45, I'll try to work it out.

Jonathan

I'm sorry I have no idea why you are getting that error, could you attach the FSH file that produced the error?

Anyway I have made a new program which does as the title of this thread says FSH<>PNG you just open a file, whether it is a PNG of FSH. And you can copy it to the clipboard as a file (.png) or a image which you can paste into a program such as paint. Also you can bulk convert and you can edit a FSH (and if you really want to a PNG) in an external app such as Paint/Photoshop and save it as a FSH without having to convert it yourself.
And it will eventually have the same drag and drop feature as the previous app did:


Jonathan

null45

The program would not crash if the code is encased in a try catch block eg.

<STAThread()> _
    Public Shared Sub Main(ByVal args As String())
        Try
            ' is there an image to convert
            If args.Length > 0 Then
                For Each a As String In args
                    Dim fi As New FileInfo(a)
                    Using fs As New FileStream(fi.FullName, FileMode.Open, FileAccess.Read)
                        Dim fsh As New FSHImage(fs)
                        Dim bi As BitmapItem = DirectCast(fsh.Bitmaps(0), BitmapItem)
                        Dim bl As New BlendBitmap()
                        Dim bmp As Bitmap = bl.BlendBmp(bi)
                        bmp.Save(Path.Combine(fi.DirectoryName, String.Concat(Path.GetFileNameWithoutExtension(fi.Name), ".png")))
                    End Using
                Next
            Else
                Interaction.MsgBox("An image must be dragged onto the program to convert it", MsgBoxStyle.Information, "No image to convert")
            End If
        Catch ex As Exception
            Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical, "Error converting file")
        End Try
    End Sub


Hopefully that helps.  :thumbsup:

puresim

#43
Quote from: Jonathan on January 16, 2010, 04:11:43 PM
I'm sorry I have no idea why you are getting that error, could you attach the FSH file that produced the error?

It's not just this program that can't open the fsh files (i.e. nothing to do with your scripting!). Here (edit: removed link) are 2 fsh files I've just saved from texture viewer in Reader, both produce the error message when dragged onto FSH2PNG.

If I'm honest I gave up trying to get it to work and just started working on another building model. My computer is telling me I have .NET framework 1, 2, 3 and 3.5 - Not sure if that is normal.

btw Jonathan I'm very interested in your new program, would be great if that worked for me.

null45

Both of those fsh files are valid and work fine for me.

What error does FiSHMan give?


puresim

In desperation I reinstalled Fishman and the FSHLib.dll file last night and finally got it to open my fsh files. I still get the same error from FSH2PNG though.

FiSHman was giving me an invalid file error before, but the new installation seems fine. Thanks for your help guys :)

Jonathan

are you using the same FSHLib.dll in both programs, try copying the one from FiSHMan folder to the FSH2PNG folder.

They work fine with the FSH2PNG on my PC.

puresim

This is embarassing but that just worked &ops I was 99.9% sure that was the latest FSHLib.dll file!

Thanks all!

Jonathan

The whole point of this tool was to make converting FSH to PNG and back to FSH again just to edit it redundant. But I got a little carried away

So this program does the same as FSH2PNG, as well as have a proper interface.

To convert FSH(s) to PNG in the same style as FSH2PNG, all you have to do is drop the FSHs onto the program icon, and hold the Control Key down as you do so. Or set the program as the default for FSH and hold Control as you open them.

Another option is to use the FSHPNGConverter - Quick Convert icon. This is just a short cut to FSHPNGConverter with the command line arguement /c.

If you don't hold Control down then it opens the FSHPNGConverter and puts the FSHs you dropped on the icon or opened into the list in the left.

To edit a FSH without converting it back and forth (the program does this automatically for you) open it in FSHPNGConverter and the select it in the list, then click Edit in App button. This lets you select the program you want to open it in (say photoshop). After that the FSHPNGConverter dissapears and the program will load with the FSH open in it. Then When you are done click save and the close (please remember to save :)). The FSHPNGConverter will reappear with the edited FSH in it. You can then click Save to save it a FSH. (So you must save it in the editing program and FSHPNGConverter )

Saving the FSH:
There are different Types of FSH, uncompressed/compressed and alpha/no-alpha and the combinations of the two. in FSHPNGConverter you just select Compressed or Uncompressed from the combobox at the bottom right.
It will see if there is an alpha or not.
The default is compressed.

You can also copy the FSH as a PNG file (that you can paste into explorer) onto the clipboard
Or copy the FSH as an image (that you can paste into MS paint etc) onto the clipboard.

You can also drag and drop FSH/PNGs onto the listview. And the program can have PNGs dragged onto it's icon/opened with it.



Jonathan

puresim

That's a lot of useful new features! :thumbsup: Looks really simple to use from the screenshot - Where can we download it from?


Jonathan

#51
Here is the FSHConverter Tool, finally got round to fixing the issue.

Quote from: Jonathan on February 15, 2010, 10:09:59 AM
The whole point of this tool was to make converting FSH to PNG and back to FSH again just to edit it redundant. But I got a little carried away

So this program does the same as FSH2PNG, as well as have a proper interface.

To convert FSH(s) to PNG in the same style as FSH2PNG, all you have to do is drop the FSHs onto the program icon, and hold the Control Key down as you do so. Or set the program as the default for FSH and hold Control as you open them.

Another option is to use the FSHPNGConverter - Quick Convert icon. This is just a short cut to FSHPNGConverter with the command line arguement /c.

If you don't hold Control down then it opens the FSHPNGConverter and puts the FSHs you dropped on the icon or opened into the list in the left.

To edit a FSH without converting it back and forth (the program does this automatically for you) open it in FSHPNGConverter and the select it in the list, then click Edit in App button. This lets you select the program you want to open it in (say photoshop). After that the FSHPNGConverter dissapears and the program will load with the FSH open in it. Then When you are done click save and the close (please remember to save :)). The FSHPNGConverter will reappear with the edited FSH in it. You can then click Save to save it a FSH. (So you must save it in the editing program and FSHPNGConverter )

Saving the FSH:
There are different Types of FSH, uncompressed/compressed and alpha/no-alpha and the combinations of the two. in FSHPNGConverter you just select Compressed or Uncompressed from the combobox at the bottom right.
It will see if there is an alpha or not.
The default is compressed.

You can also copy the FSH as a PNG file (that you can paste into explorer) onto the clipboard
Or copy the FSH as an image (that you can paste into MS paint etc) onto the clipboard.

You can also drag and drop FSH/PNGs onto the listview. And the program can have PNGs dragged onto it's icon/opened with it.



Jonathan

Jonathan

null45

Getting a System.NullReferenceException when the form loads, it will run if continue is clicked.


Jonathan

#53
Great, that's what I though I'd fixed.

EDIT: Forgot a Not :)

I've updated it and it's attached to the same post,

null45

The Alpha from Transparency code contains another bug, it would not set the alpha map on semi-transparent sections of an image.

The fixed code is:

    While testbmp.GetPixel(x, y).A < 255
        testbmp.SetPixel(x, y, Color.FromArgb(srcpxl.A, srcpxl.A, srcpxl.A))
   End While


Jonathan

#55
Are you saying I should replace this:

  While testbmp.GetPixel(x, y).A = 0 AndAlso testbmp.GetPixel(x, y).R = 0
                    testbmp.SetPixel(x, y, Color.Black)
                End While

with that? Because you gave me this code.

And I'm not really sure what you mean by it would not set the alpha map on semi-transparent sections of an image? Is that opening or saving a FSH or a PNG?

null45

#56
It would be all of them.

The 24-bit fsh would need to have its alpha reset to white when loaded or it would cause the image to disappear when Alpha Blended.



Jonathan

Well I fixed the semi-transparency thing, though I didn't use your code as I said in the PM. Please let me know if that was wrong :)

Also added in a show Alpha button which shows you the alpha of the selected image (not when you've selected multiple though) in a little toolbox type window.

Also lets you save in 24-bit uncompressed properly, and thanks to null45's fix he sent me ages ago you can now open 24-bit uncompressed FSHs and they will be correct.

Before I reupload I'm going to add a an "Add alpha to image" button so that you can open a bitmap then right click it and choose an alpha for it.

Also going to add a quick edit feature, which works the same the quick convert does and will allow you to open in programs that do not support photoshop without seeing any of the FSHConverter program.

Also change the way the compression setting works, by making it remember if the FSH you opened was compressed or not. And make it easier to see which are compressed and which aren't.

Jonathan

puresim

Sounds good mate, looking forward to it :thumbsup:

Jonathan

Much smaller easier tool, going back to what I was originally wanting (simple tools to use FSH files)

Simply adds a convert button to the context menu and explorer bar to convert the FSH: