Jump to content
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted

Hi all,

I am making a PC port of a Nintendo Game & Watch hand-held game called "Mario Bros."; see this sped up youtube video of the game being played

http://au.youtube.com/watch?v=--zl4Fl5IqU

Anyway, I have a bitmap containing all the LCD sprites (black bits making up the characters, etc). that I need to enable/disable via the game code to create the animation sequences and I now want to separate the sprites into separate bitmaps.

To make my life easier I wanted to see if I could make a Paint.NET plugin that would take the current selection from my LCD bitmap and save all the rectangular regions of that selection to a text file so I can then more easily create the separate 'sprites' needed for the game.

This means that I can exactly recreate the separate sprites and know exactly where they need to be positions just from the coordinates in that text file exported via the plugin.

I have tried using CodeLAB and the test code below:

    StreamWriter SW;
   SW = File.AppendText("C:\\MyTextFile.txt");
   SW.WriteLine("This Line Is Appended");
   SW.Close();

but CodeLAB gives me these errors:

"The Type or namespace 'StreamWriter' could not be found..."

"The name 'File' does not exist in the current context..."

Any ideas?

Do I need to use Visual Studio 2005/2008 Express or simular instead?

cheers,

Paul

Posted

Try this code:

System.IO.StreamWriter SW;
SW = System.IO.File.AppendText("C:\\MyTextFile.txt");
SW.WriteLine("This Line Is Appended");
SW.Close();

I don't think there is a way to add using statements to CodeLab plugins.

KaHuc.png
Posted
Try this code:

System.IO.StreamWriter SW;
SW = System.IO.File.AppendText("C:\\MyTextFile.txt");
SW.WriteLine("This Line Is Appended");
SW.Close();

I don't think there is a way to add using statements to CodeLab plugins.

Wow! That was a fast response, thanks!

Unfortunately, now I am getting this error from CodeLAB (during it's compile) and Paint.NET if I save as DLL and try running it that way instead:

System.IO.IOException: The process cannot access the file 'C:\MyTextFile.txt' because it is being used by another process.

Any ideas?

It seems more likely that I am going to have to move to Visual Studio instead...

cheers,

Paul

Posted
Remember, the render function is called hundreds of times (at the same time). So, you should check to see if you are working on a specific pixel before proceeding and just return the other times.

if ((0 == x) && (0 == y))
{
   // process your file
}

Hi BoltBait, even with the render function being called hundreds of times, wouldn't each selection be unique?

My plugin code below still gives me the same error when run even thought the file names should be unique each time I would have thought:

void SaveSelectionToFile(Rectangle rect)
{
   String str = String.Format("C:\\Sprites\\{0},{0},{0},{0}",
                                   rect.Left.ToString(),
                                   rect.Top.ToString(),
                                   rect.Right.ToString(),
                                   rect.Bottom.ToString());

   String filename = str + ".txt";

   if (System.IO.File.Exists(filename) == true) return;
   System.IO.StreamWriter SW;
   SW = System.IO.File.CreateText(filename);
   SW.WriteLine(str);
   SW.Close();
}

void Render(Surface dst, Surface src, Rectangle rect)
{
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   SaveSelectionToFile(selection);
}

Full Error:

File: C:\Program Files\Paint.NET\Effects\SaveSelection.dll
     Name: SaveSelectionEffect.SaveSelectionEffectPlugin
     Version: 1.0.3303.23127
     Author: 
     Copyright: Copyright © 
     Website: http://www.getpaint.net/redirect/plugins.html
     Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.IO.IOException: The process cannot access the file 'C:\Sprites\228,228,228,228.txt' because it is being used by another process.
  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
  at System.IO.StreamWriter.CreateFile(String path, Boolean append)
  at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
  at System.IO.StreamWriter..ctor(String path, Boolean append)
  at System.IO.File.CreateText(String path)
  at SaveSelectionEffect.SaveSelectionEffectPlugin.SaveSelectionToFile(Rectangle rect)
  at SaveSelectionEffect.SaveSelectionEffectPlugin.Render(Surface dst, Surface src, Rectangle rect)
  at SaveSelectionEffect.SaveSelectionEffectPlugin.OnRender(Rectangle[] rois, Int32 startIndex, Int32 length)
  at PaintDotNet.Effects.Effect`1.Render(Rectangle[] renderRects, Int32 startIndex, Int32 length)
  at PaintDotNet.Effects.Effect`1.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length)
  at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderImpl()
  --- End of inner exception stack trace ---
  at PaintDotNet.Effects.BackgroundEffectRenderer.Join()
  at PaintDotNet.Menus.EffectMenuBase.DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion, PdnRegion regionToRender, Surface originalSurface, Exception& exception)

cheers,

Paul

Posted

So does ANYONE know how I could make very basic plugin (effect, or similar) for Paint.NET that will take a current selection and write all the selection parts to a text file for later use?

An example text file output might be (containing all the selection parts for the whole selection):

.txt

(left,top,right,bottom),(left,top,right,bottom),(left,top,right,bottom),(left,top,right,bottom),....

Obviously I don't understand Paint.NET enough to get this working :(

cheers,

Paul

  • 6 years later...
Posted (edited)

I know this topic is old, but I used it for making my own plugin as I'm not too handy with c# and wasn't aware that codelab  could use this code. Thanks!

 

Oh yeah, I think codelab's debugger runs the code constantly (like a spreadsheet), so maybe that was the access error? Works fine with an IF statement tho.

       int CPR = CPIX.R;
       if (CPR == 100)              { //START: CPR IF
         System.IO.StreamWriter SW;
         SW = System.IO.File.AppendText("C:\\Users\\CTCPublic\\Desktop\\geb\\CoolEdit.txt");
         SW.WriteLine("R:" + CPR + "," + "G:" + CPG + "," + "B:" + CPB + " |" +
                      "H:" + CPH + "," + "S:" + CPS + "," + "V:" + CPV + " |" + 
                      "coords=" + "V:" + V + "H:" + H);
        SW.Close();
                                    } //END: CPR IF
Edited by denverpotsmoker

The Rise of the Creative Class

by: Richard Florida

Posted

Thread is six years old. We've had several updates to both paint.net and CodeLab in that time.

I'm going to lock this because reviving long dead discussions is not helpful. Please just start a new thread if you wish to revisit a topic.

Thanks.

<locked>

Guest
This topic is now closed to further replies.
×
×
  • Create New...