Sign in to follow this  
TechnoRobbo

TR's Export Selection

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

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: .

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

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

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

  • Upvote 1

Share this post


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

Sign in to follow this