Jump to content
How to Install Plugins ×

TR's Export Selection


TechnoRobbo

Recommended Posts

TechnoRobbo's Export Selection


Exports irregular shaped selections to PNG


 


v1.2 - Persistent Folder


V1.1 - Code Clean up - avoids potential memory hole.


 


Menu: Effects->Selection



 


 


Source Code for CodeLab


Hidden Content:



// Submenu: Selection
// Name: TR's Export Selection
// Title: TR's Export Selection- v1.2
// Author: TechnoRobbo
// URL: http://www.technorobbo.com


System.Drawing.Bitmap bMap;
private void savepng()
{
    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(saver));
    t.SetApartmentState(System.Threading.ApartmentState.STA); 
    t.Start();
    t.Join();   
}


private string GetFileName()
{
    System.Windows.Forms.SaveFileDialog OpenFileDialog1= new System.Windows.Forms.SaveFileDialog();
    string fp = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("TechnoRobbo");


    if (rk != null)
    {
        try
        {
            fp = (string)rk.GetValue("ExportSelectionPath");
            if (!System.IO.Directory.Exists(fp)) fp = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);


        }
        catch
        {
            fp = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        }
    }


    OpenFileDialog1.InitialDirectory = fp;
    OpenFileDialog1.Filter = "PNG file (*.png)|*.png";
    OpenFileDialog1.FilterIndex = 1;
    OpenFileDialog1.RestoreDirectory = false;
    if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
    {
        Microsoft.Win32.RegistryKey key;
        key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("TechnoRobbo");
        key.SetValue("ExportSelectionPath", System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName));
        key.Close();
        return OpenFileDialog1.FileName;
    }
    return String.Empty;


}


private void saver()
{


     string fp = GetFileName();//Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
     if ( !fp.Equals( String.Empty))
     {
       bMap.Save(fp);
     }
}


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


    if (IsCancelRequested) return;
    SignalCancelRequest();
    System.Windows.Forms.Application.DoEvents();
    
    bMap =new Bitmap(selection.Width, selection.Height);
    string fp = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                


    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
    try
    {
        Graphics g = Graphics.FromImage(bMap);
        Region reg = new Region(selectionRegion.GetRegionData());
        reg.Translate(-selection.Left, -selection.Top);
        g.SetClip(reg, System.Drawing.Drawing2D.CombineMode.Replace);
        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        GraphicsUnit units = GraphicsUnit.Pixel;
        g.DrawImage(src.CreateAliasedBitmap(),new Rectangle(0,0,selection.Width, selection.Height), selection ,units);
        g.Dispose();
        reg.Dispose();
        savepng();
    }
    catch { }
}


 


TRsExportSelection.zip

  • Upvote 6

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

TechnoRobbo!   <3 Today: (You have reached your quota of positive votes for the day) But tomorrow determined. :)  This is a awesome plugin. Thank you very much. qgrm4bj9.gif

Live as if you were to die tomorrow. Learn as if you were to live forever.

Gandhi

 

mae3426x.png

Link to comment
Share on other sites

  • 10 months later...

Very nice and useful, TR!Laie_98.gif

 

Would it be possible to make it remember the last save path? (just if it's not too much of a hassle)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...