TechnoRobbo Posted September 6, 2014 Share Posted September 6, 2014 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 Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
DrewDale Posted September 6, 2014 Share Posted September 6, 2014 Nice work TR Quote Link to comment Share on other sites More sharing options...
Pixey Posted September 6, 2014 Share Posted September 6, 2014 Oh what a great time-saver this is going to be. Thankies x a million . Quote How I made Jennifer & Halle in Paint.net My Gallery | My Deviant Art "Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon. Link to comment Share on other sites More sharing options...
Seerose Posted September 7, 2014 Share Posted September 7, 2014 TechnoRobbo! Today: (You have reached your quota of positive votes for the day) But tomorrow determined. This is a awesome plugin. Thank you very much. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi Link to comment Share on other sites More sharing options...
TechnoRobbo Posted September 7, 2014 Author Share Posted September 7, 2014 Thank You Pixey and Seerose 1 Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
midora Posted September 7, 2014 Share Posted September 7, 2014 Please add a Dispose for the region (it is unmanaged) or even better use using for Graphics and Region. 1 Quote Link to comment Share on other sites More sharing options...
TechnoRobbo Posted September 7, 2014 Author Share Posted September 7, 2014 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 Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
Maximilian Posted July 8, 2015 Share Posted July 8, 2015 Very nice and useful, TR! Would it be possible to make it remember the last save path? (just if it's not too much of a hassle) Quote Link to comment Share on other sites More sharing options...
TechnoRobbo Posted July 9, 2015 Author Share Posted July 9, 2015 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 Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
Maximilian Posted July 9, 2015 Share Posted July 9, 2015 Thank you very much, TR! You are a super person! Quote Link to comment Share on other sites More sharing options...
TechnoRobbo Posted July 9, 2015 Author Share Posted July 9, 2015 Aw-Shucks. Quote Go out there and be amazing. Have Fun, TRSome Pretty Pictures Some Cool Plugins Link to comment Share on other sites More sharing options...
Maximilian Posted July 9, 2015 Share Posted July 9, 2015 Happy news to report as it's working perfectly! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.