RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

[RunUO 2.0 RC1] RunUO Image Converter

Joeku

Lord
[RunUO 2.0 RC1] RunUO Image Converter


Version 1.0


Description
The RunUO Image Converter is based off of Serp's ImageCreator and alambik's ShowIcon Command. A seperate executable program lets you convert normal Bitmap images into usable RunUO code, so you can use them straight in your gumps, patch-free!

Features
  • Converts Bitmap images into RunUO code, usable by gumps.
  • Easy-to-use interface.
  • Seperate executable program.
  • Requires Ultima Online installation.
Changelog
  • Version 1.0 August 20, 2006 - Initial release.
Installation/Use
First, download "RunUO Image Converter.zip". Extract the files to any folder you want, and put BaseImageGump.cs in your Scripts folder.
Second, run "RunUO Image Converter.exe". Open a Bitmap image, and click "Generate". You will find your script in the filepath shown to you in the Reports field. Your script should look similar to this:
Code:
//Generated by RunUO Image Converter v1.0
//Created by Joeku
//8/20/2006 11:45:35 PM

using System;
using Server;

namespace Joeku
{
	public class Avatar : BaseImageGump
	{
		public static int X = 80;
		public static int[] Values = new int[]
			{ 1174, 1174, 1174, 1174, 1174, 1174, 1174, ... };
		public static void AddToGump( Gump gump, int xOffset, int yOffset, int PixelSize )
		{ BaseAddToGump( gump, xOffset, yOffset, X, PixelSize, Values ); }
	}
}
When you "add" this to your gump, do it like so:
Code:
	public class CustomImage : Gump
	{
		public CustomImage() : base( 0, 0 )
		{
			AddPage(0);
			[COLOR="Red"]Avatar[/COLOR].AddToGump( this, 0, 0, 1 );
		}
	}
Replace the code in red with your ImageGump class name. The ( this, 0, 0, 1 ) stands for: ( Gump gump, int X, int Y, int PixelSize ). PixelSize is not yet an active feature. X and Y are the coordinates which you want to add the image to your gump. Please note that, currently, this lags somewhat with images (lag increases as image size increases). A 32x32 image shouldn't lag. This lag problem may be resolved with future clients and/or program updates.

Known Drawbacks/Bugs
  • Progress bar flashes while working.
  • Some potential crash-prevention code has not yet been added.
  • Some lag problems exist.
Coming Soon
  • Transparency support.
Thank you for downloading this program. E-mail comments/suggestions, or post them here.

NOTE: This is the very first release; it is definitely NOT bug-free. Your cooperation is needed for me to perfect this program.
I will release the source code soon, once I clean it up a bit.
 

Attachments

  • RunUO Image Converter.zip
    11.2 KB · Views: 241
  • ImageConverter_1.png
    ImageConverter_1.png
    10.4 KB · Views: 276
  • ImageConverter_2.PNG
    ImageConverter_2.PNG
    20.6 KB · Views: 290
  • ImageConverter_3.PNG
    ImageConverter_3.PNG
    21.7 KB · Views: 397

pacolaco2

Sorceror
OMfg crash!!!

Just kidding. It's a great program, it kicks lots of ass, and only gave me three trojans!

Ps. Just kidding, no trojans.
 

Joeku

Lord
You can use your images in UO Gumps. For instance, you can put your shard logo on your MOTD.

You can NOT make new items, mobiles, or any other type of interactive art.
 

Jeff

Lord
Joeku, very cool, but can u fix your progress bar please? :)

If you need help lemme know

Also for me the stream doesnt close till the application is exited, instead it should close when the operation is complete :)
 

Joeku

Lord
I found the fix for the progress bar... I'll show you:
Code:
        public static void BitmapInformation(string filename, MainForm form)
        {
            try
            {
                using (Bitmap bitmap = new Bitmap(filename))
                {
                    form.Output.Write("			{ ");
                    for (int y = 0; y < bitmap.Height; y++)
                        for (int x = 0; x < bitmap.Width; x++)
                        {
                            // get the color of the pixel at (x, y)
                            Color col = bitmap.GetPixel(x, y);

                            int colorIndex = 0;
                            int leastDistance = int.MaxValue;
                            int red = col.R;
                            int green = col.G;
                            int blue = col.B;

                            int invalidIndex = 0;

                            // Loop through the entire palette,
                            // looking for the closest color match
                            for (int index = 0; index < m_Palette.Length; index++)
                            {
                                // skip invalid hues
                                if (invalidIndex < m_InvalidRanges.Length / 2 && m_InvalidRanges[2 * invalidIndex] == index)
                                {
                                    index = m_InvalidRanges[2 * invalidIndex + 1];
                                    invalidIndex++;
                                    continue;
                                }

                                // Lookup the color from the palette
                                Color paletteColor = m_Palette[index];

                                // Compute the distance from our source color to the palette color
                                int redDistance = paletteColor.R - red;
                                int greenDistance = paletteColor.G - green;
                                int blueDistance = paletteColor.B - blue;

                                int distance = (redDistance * redDistance) +
                                    (greenDistance * greenDistance) +
                                    (blueDistance * blueDistance);

                                // If the color is closer than any other found so far, use it
                                if (distance < leastDistance)
                                {
                                    colorIndex = index;
                                    leastDistance = distance;

                                    // And if it's an exact match, exit the loop
                                    if (0 == distance)
                                        break;
                                }
                            }
                            [COLOR="Red"]form.progressBar1.Value = (int)Math.Floor((double)((x * y) / ((bitmap.Height * bitmap.Width) / 100)));[/COLOR]
                            //form.progressBar1.Update();
                            form.Output.Write( (colorIndex).ToString() + ", ");
                        }

                    form.Output.Write(" };");
                }
            }
            catch (Exception e) { Console.WriteLine("catch({0})", e.Message); }
        }
The code where the progress bar's value is updated is in red. It multiplies x and y, and then rounds them down and divides them to find the percentage. What I didn't count on is, with this for() loop, y is frequently "0". Obviously, there's a simple fix for that ;)
 

Jeff

Lord
Awsome, what about erm, closing the stream to the file upon writing to it?

what i would do is, this

at the top where u define m_Output make it like this

Code:
StreamWriter m_Output = null;//Has to be null.

Then you can use a try catch finally
Code:
      try
      {
            this.m_Output = new StreamWriter(Path.Combine(text1, this.textBox1.Text.Trim() + ".cs"), true);
            this.m_Output.AutoFlush = true;
            this.m_Output.WriteLine("//Generated by RunUO Image Converter v1.0");
            this.m_Output.WriteLine("//Created by Joeku");
            this.m_Output.WriteLine("//{0}", DateTime.Now);
            this.m_Output.WriteLine();
            this.m_Output.WriteLine("using System;");
            this.m_Output.WriteLine("using Server;");
            this.m_Output.WriteLine();
            this.m_Output.WriteLine("namespace Joeku");
            this.m_Output.WriteLine("{");
            this.m_Output.WriteLine("\tpublic class {0} : BaseImageGump", this.textBox1.Text.Trim());
            this.m_Output.WriteLine("\t{");
            this.m_Output.WriteLine("\t\tpublic static int X = {0};", this.MyImage.Width);
            this.m_Output.WriteLine("\t\tpublic static int[] Values = new int[]");
            BitmapHelper.BitmapInformation(this.FilePath, this);
            this.m_Output.WriteLine();
            this.m_Output.WriteLine("\t\tpublic static void AddToGump( Gump gump, int xOffset, int yOffset, int PixelSize )");
            this.m_Output.WriteLine("\t\t{ BaseAddToGump( gump, xOffset, yOffset, X, PixelSize, Values ); }");
            this.m_Output.WriteLine("\t}");
            this.m_Output.WriteLine("}");
            this.textBox2.Text = string.Format("Save: {0}\n\nSave Successful!\n{1}\n------------------------------------------\n", text1 + @"\" + this.textBox1.Text.Trim() + ".cs", DateTime.Now) + this.textBox2.Text;
            this.Generating = false;
            this.button1.Text = "Generate";
            this.button2.Show();
      }
      catch (Exception exception1)
      {
            this.textBox2.Text = string.Format("Save: {0}\nERROR: {1}\n------------------------------------------\n", Path.GetFileName(this.FilePath), exception1.Message) + this.textBox2.Text;
            Console.WriteLine(exception1.Message);
            this.Generating = false;
            this.button1.Text = "Generate";
            this.button2.Show();
      }
      finally
      {
            if( m_Output != null )
                m_Output.Close(); 
      }
}
 

Joeku

Lord
daat99 breakin' it down nice and easy why my Image Converter got moved to Third Party Program Support:
Code:
[21:35] Demortris: hey wouldn't ArteGordon's Spawn Editor 2 [url]http://www.runuo.com/forums/showthread.php?t=70757[/url] also not be classified as a "script" and moved to Third Party Program Support? 

[20:58] daat99: added the transferserver-20-v105a.rar package that contains the TransferServer scripts that works under RunUO 2.0. [Offline Message (8/29/2006 [12:30])]
[20:58] daat99: notice "transferserver scripts", it is a tool but it also a script package [Offline Message (8/29/2006 [12:30])]
[20:58] daat99: basically he have the same spawner scripts but he also added an external editor, if I understand it correctly you don't even have to use the external editor for it to work [Offline Message (8/29/2006 [12:31])]

[21:00] Demortris: :P
[21:01] Demortris: my RunUO Image Converter comes with scripts... and the external utility isn't REQUIRED for it to work
[21:01] Demortris: it just makes editing a LOT easier *lol*
[21:01] daat99: doesn't the image converter create scripts from images?
[21:01] Demortris: it does
[21:01] Demortris: but you dont have to use it to make a GumpImage
[21:02] Demortris: I made a beta GumpImage by hand
[21:02] Demortris: if you wanted to, you could build your GumpImage in-game on the floor
[21:02] Demortris: and manually transfer the hues
[21:02] daat99: let me explain it this way
[21:02] daat99: can you use image converter without RunUO?
[21:02] Demortris: the utility can be used without RunUO
[21:02] daat99: exactly
[21:02] Demortris: but it's useless without the base scripts that come with it
[21:03] daat99: you can't use the spawn editor without installing the scripts for it first
[21:03] Demortris: ?
[21:03] daat99: the spawn require scripts to work, your image converter doesn't
[21:03] Demortris: oh so
[21:04] daat99: besides what I already said that you don't have to use the spawn editor at all, it's just an extra
[21:04] Demortris: his utility actually uses the RunUO scripts in active time?
[21:04] Demortris: :O
[21:04] daat99: if you want to edit spawns than it communicate with his scripts
[21:04] daat99: if you don't have the scripts installed and running on your shard than the tool is preaty much useless
[21:04] daat99: (that's what I understand from his description anyway)
[21:04] Demortris: same with my Image Converter
[21:04] Demortris: but it's just one script that you have to have installed :P
[21:04] daat99: no it isn't the same
[21:04] Demortris: yes sir
[21:05] Demortris: just on a completely different scale
[21:05] Demortris: lol
[21:05] daat99: your image converter main goal is to make scripts with an external tool
[21:05] daat99: his main goal is to spawn the world after installing scripts
[21:05] daat99: his tool is for convinience, yours isn't
[21:05] daat99: your external tool is the main reason you opened the thread
[21:06] Demortris: >_<butIwantitinthescriptsubmissionsboard!<--crybaby
[21:07] daat99: than release a script that does it
[21:07] Demortris: cant
[21:07] Demortris: RunUO uses too much server power
[21:07] Demortris: it crashes the shard
[21:07] daat99: so it isn't a script after all ;)
[21:07] Demortris: it generates scripts
[21:07] Demortris: and and and
[21:07] Demortris: you have to have UO installed if that makes a difference
[21:07] Demortris: lol
[21:07] daat99: well generating scripts tools are in the 3rd partty section
[21:08] daat99: look at "script magic" it generate scripts as well
[21:08] daat99: it was also posted in the script release forum and moved to the 3rd party section
[21:08] daat99: it isn't a script, it  makes scripts
[21:08] Demortris: his spawn editor generates XML files
[21:09] daat99: but his script use those xml files
[21:09] daat99: he post the thread to release the scripts and added a tool to make it easier to modify
[21:09] Demortris: SO 
[21:09] Demortris: if I post a thread 
[21:09] daat99: you didn't released a script, you released a tool that make scripts
[21:09] Demortris: with stock Gump Images 
[21:10] Demortris: then mine counts as a tool to make it easier to modify? 
[21:10] Demortris: =D 
[21:10] daat99: than it won't be called image converter, it'll be called "stock gump images"
[21:10] daat99: if you want to post a thread called "gump images" than go right ahead
[21:10] daat99: if you name it "image converter" than it's clear that you release a TOOL and not a SCRIPT
[21:10] Demortris: lol
[21:11] Demortris: you're just making it difficult for me :(
[21:11] Demortris: ah well, nothing to be done
[21:11] Demortris: Arte wins again
[21:11] daat99: nop, you're making it difficult to me ;)
[21:11] daat99: let's think about this
[21:11] daat99: can you make egg salad from a chicken?
[21:11] Demortris: wha-?
[21:12] daat99: egg salad
[21:12] Demortris: no, but you can use the products of the chicken to make egg salad
[21:12] Demortris: ...
[21:12] daat99: but you can't make egg salad from the chicken itself, can you?
[21:12] daat99: what you say is this: 
[21:12] Demortris: I can use the chicken to make the egg salad!
[21:12] Demortris: a chicken is better than eggs!
[21:12] daat99: I want to sell a chicken and label it as "egg for egg salad"
[21:12] Demortris: lmfao
[21:12] daat99: no you can't
[21:13] Demortris: okay okay I get your point
[21:13] daat99: you need to wait for the chicken to give you an egg first
[21:13] Demortris: lmao
[21:13] daat99: and than you use the EGG and not the chicken itself
:(

Side note: the modifications are almost complete, and while I'm at it I'm cleaning up the source code. Both should be released in a little while. Turns out, the Progress Bar issue was completely different...
 

kmwill23

Sorceror
Joeku's account really terminated? I want to ask to use this in Chat!

Addition: Colors show up a bit wierd, takes a tad too long to render. Shucks!
 
kmwill23 said:
Joeku's account really terminated? I want to ask to use this in Chat!

Addition: Colors show up a bit wierd, takes a tad too long to render. Shucks!
Aye the first one was for advertising not sure what the most recent one was, but he was unbanned for about a day before it went back. I'd hit him up via IM or other outside channels.
 

Kami-jin

Wanderer
Could someone explain the basics to using this?

Or, could someone show me how to use a script to display a file generated by this, cause using the one posted above gives my errors.
 

Joeku

Lord
Kami-jin;639679 said:
Could someone explain the basics to using this?

Or, could someone show me how to use a script to display a file generated by this, cause using the one posted above gives my errors.
Don't use the one posted above; download the file and drop BaseImageGump.cs into your custom scripts folder. Then generate your image and drop the generated file (whatever you named it) into your scripts folder, and access that.
Kenko;639718 said:
Good job Joe.

Does this work with JPGs aswell?

<3.
As far as I know, it only works with .BMPs. You're welcome to try though.

Yeah the project sorta died... since nobody was using it and it was *way* laggier than I expected. I'll still post the update and source code that I promised (eventually), though.
 

Kami-jin

Wanderer
Alright. Dropped BaseImageGump.cs in Scripts directory, Generated my image, and put it in my scripts folder.

Now it's causing errors:
Line 15: The Type or namespace 'Gump' could not be found (are you missing a using directive or an assembly reference?)"

How the hell do you access it?
 
Top