Sign in to follow this  
Followers 0
TechnoRobbo

TR's Export Selection

12 posts in this topic

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

6

Share this post


Link to post
Share on other sites

thumbsup.gif   Oh what a great time-saver this is going to be.  Thankies x a million :beer: .

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

Please add a Dispose for the region (it is unmanaged) or even better use using for Graphics and Region.

1

Share this post


Link to post
Share on other sites

 

Midora - 

 

Please add a Dispose for the region (it is unmanaged) or even better use using for Graphics and Region.

Agreed. Good catch - thought I did but I only disposed g.

 

V1.1 Uploaded

0

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

 

 

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

No hassle at all Maximilian

 

Version 1.2 ready for Download

persistent Save Folder

1

Share this post


Link to post
Share on other sites

Thank you very much, TR! You are a super person! yes2.gifLaieA_017.gif

0

Share this post


Link to post
Share on other sites

JC_cheesy.gif

 

Happy news to report as it's working perfectly! LaieA_060.gif

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0