Editable Image Region

Editable Image Region - Messages

#81 Posted: 2/9/2016 2:14:50 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

EDIT not tested, but should works:
           MenuButton FileType = new MenuButton("File Type";

           string[] extension = new string[] { "*.png", "*.svg", "*.psd", "*.pdf", "*.dxf", "*.dwg" };

           for (int i = 0; i < extension.Length; i++)
           {
               FileType.AppendChild(extension[0], delegate(MenuButtonArgs args)
                                    {
                                        ((ImageEdit.ImageRegion)args.CurrentRegion).GetCanvas().select_ext = extension[i];
                                    });

               if (((ImageEdit.ImageRegion)args.CurrentRegion).GetCanvas().select_ext == extension[i])
                   FileType.Children[i].Checked = true;
           }[/code][/quote]

For some reason I could not run this line (with text "args" being highlighted as an error:

[code=csharp]if (((ImageEdit.ImageRegion)args.CurrentRegion).GetCanvas().select_ext == extension[i])

I did a workaround:

MenuButton FileType = new MenuButton("File Type";

            string[] extension = new string[] { "*.png", "*.svg", "*.psd", "*.pdf", "*.dxf", "*.dwg" };

            string chck = "*.png";

            for (int i = 0; i < extension.Length; i++)
            {
                
                FileType.AppendChild(extension[i], delegate(MenuButtonArgs args)
                {
                    ((ImageEdit.ImageRegion)args.CurrentRegion).GetCanvas().select_ext = extension[i];
                    chck = ((ImageEdit.ImageRegion)args.CurrentRegion).GetCanvas().select_ext;
                });

                if (chck == extension[i])
                    FileType.Children[i].Checked = true;
            }

And it did not work - as soon as I click on one of the file extension menu items I get "Index was outside the bounds of the array".

Okay, the code works now. The only hiccup is that I cannot reference any of my variables defined in
namespace ImageEdit
{
    class ImageCanvas : RegionEvaluable
Which is an upset. I am sure I am missing something basic

Ughh...
So now if I click on one of the menu items, it remembers my section for the next blank region I insert. Bummer
#82 Posted: 2/9/2016 3:45:10 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Implemented in-memory image rotation. Mildly useful when you need to fit landscape image to a portrait page without altering the source file.

Still cannot make checkmarks for context menu items work.

ImageRegion.009.zip (74 KiB) downloaded 66 time(s).
#83 Posted: 2/9/2016 5:04:01 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Sorry, previous code was made on the fly, this is tested:

            ImageCanvas canvas = ((ImageRegion)context.CurrentRegions[0]).GetCanvas();
            MenuButton FileType = new MenuButton("Blank File Type";

            string[] extension = new string[] { "*.png", "*.svg", "*.psd", "*.pdf", "*.dxf", "*.dwg" };

            for (int i = 0; i < extension.Length; i++)
            {
                FileType.AppendChild(extension[i], delegate(MenuButtonArgs args)
                                     {
                                         ImageCanvas c = ((ImageRegion)args.CurrentRegion).GetCanvas();
                                         c.select_ext = (string)args.MenuButton.Data;
                                     });

                FileType.Children[i].Data = extension[i];

                if (canvas.select_ext == extension[i])
                    FileType.Children[i].Checked = true;
            }

Wrote

The workflow for image type selection is:

1. Select the extension (.png is preselected)
2. Double click empty region
3. Blank file will be created on the fly (if no file exists already)

It might make more sense to rename the button to Blank File Type.


I think could be hidden (not added in MenuButton[] contextMenuItems) if an external image is already loaded

Wrote

Also do you think that "open with" on double click is better than open? Sounds like extra step..


May be added as another option ("Open with...") - obviously if that code works
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#84 Posted: 2/9/2016 5:12:10 AM
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 likes in 1708 posts.

Group: Moderator

Alex, ask Andrey make access to the repository. It is possible to change access permissions to plugin. You will be able to make changes and we can watch for this.
Russia ☭ forever, Viacheslav N. Mezentsev
2 users liked this post
Davide Carpi 2/9/2016 6:15:00 AM, Alexander O. Melnik 2/9/2016 1:51:00 PM
#85 Posted: 2/10/2016 2:58:30 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Alex, ask Andrey make access to the repository. It is possible to change access permissions to plugin. You will be able to make changes and we can watch for this.



Will do! Once Its more or less ready to go..

#86 Posted: 2/10/2016 3:00:52 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

All done for OpenAs and disabling file type once file exists. I had to butcher up the code to get OpenAs to work (converting "create file" and "open" to two separate functions that are called by double clicking or context menu Open As...) so there might be some new bugs.

ImageRegion.011.zip (78 KiB) downloaded 59 time(s).
1 users liked this post
Davide Carpi 2/10/2016 7:38:00 PM
#87 Posted: 2/10/2016 7:36:25 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Nice

I think the text of "Open as..." would be better as "Open with..."

I noticed also that the end of the resize logic should be improved; maybe something like this:

		private bool IsResizing;

		// ...

		public override void OnMouseDown(MouseEventArgs e)
		{
			if (this.GetCursorType(e) != CursorType.Arrow)
			{
			    this.IsResizing = true;
			    // ...
			}

			// ...
		}

		public override void OnMouseUp(MouseEventArgs e)
		{
			if (this.IsResizing)
			{
			    this.IsResizing = false;
			    // Update logic
			    // ...
			    this.Invalidate();
			}

			// ...
		}
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#88 Posted: 2/10/2016 8:35:41 PM
kilele

kilele

133 likes in 397 posts.

Group: User

Hi all. Sorry if this is off-topic
You may have already tried these .Net components to display SVG:
https://lasithapetthawadu.wordpress.com/2014/02/24/using-vector-svg-graphics-in-c-net/
https://github.com/vvvv/SVG
http://www.codeproject.com/Articles/127039/SharpVectors-SVG-Reloaded-An-Introduction
A dirty alternative could be saving drawings in psd format and displaying them in Smath by means of a conversion process transparent to the user.
Thanks.
#89 Posted: 2/10/2016 11:54:03 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Hi all. Sorry if this is off-topic
You may have already tried these .Net components to display SVG:
https://lasithapetthawadu.wordpress.com/2014/02/24/using-vector-svg-graphics-in-c-net/
https://github.com/vvvv/SVG
http://www.codeproject.com/Articles/127039/SharpVectors-SVG-Reloaded-An-Introduction
A dirty alternative could be saving drawings in psd format and displaying them in Smath by means of a conversion process transparent to the user.
Thanks.



Not offtopic at all :-)

Original image region uses "SharpVectors" library, which seems not to be able to support document scaling for svg files that contain width/height parameters.

I use "SVG" library, which scales great, but has its own documented bug. You cannot render bitmaps larger than ~100 kB that are included in SVG file. Which is OK, considering SVG is for vector graphics.
#90 Posted: 2/10/2016 11:59:09 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Nice

I think the text of "Open as..." would be better as "Open with..."

I noticed also that the end of the resize logic should be improved; maybe something like this:

		private bool IsResizing;

		// ...

		public override void OnMouseDown(MouseEventArgs e)
		{
			if (this.GetCursorType(e) != CursorType.Arrow)
			{
			    this.IsResizing = true;
			    // ...
			}

			// ...
		}

		public override void OnMouseUp(MouseEventArgs e)
		{
			if (this.IsResizing)
			{
			    this.IsResizing = false;
			    // Update logic
			    // ...
			    this.Invalidate();
			}

			// ...
		}



I incorporated your suggestion and than some :-) Now scaling / rotation works as expected. BTW I have also somewhat documented / cleaned up my code. Please take a look - this is how it will go to the SVN (after I disable/comment out pdf/dxf/dwg support).ImageRegion.012.zip (75 KiB) downloaded 60 time(s).
1 users liked this post
Davide Carpi 2/11/2016 5:39:00 AM
#91 Posted: 2/12/2016 12:30:28 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Davide, is there a way to get indicate to Smath that image has changed (rotated) and workbook must be saved before closing? Right know if you rotate the image and close the workbook no prompt comes up to save the .sm file
#92 Posted: 2/12/2016 1:00:02 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Alex,

Can you rotate this image by some degree [let say 30].

Jean

Rotate Image Test Alex.sm (245 KiB) downloaded 67 time(s).
1 users liked this post
Alexander O. Melnik 2/12/2016 1:45:00 PM
#93 Posted: 2/12/2016 4:52:46 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Wrote

Davide, is there a way to get indicate to Smath that image has changed (rotated) and workbook must be saved before closing? Right know if you rotate the image and close the workbook no prompt comes up to save the .sm file



Hello Alex,

sure, you have to implement your own HistoryStep class that extends the built-in HistoryStepBase;

Look for example the NumericUpDownRegion

- The core: NumericUpDownHistoryStep.cs

- In the region holder:
        // ...

        public override HistoryStepBase GetHistoryStep()
        {
            return new NumericUpDownHistoryStep(this);
        }

        // ...

- After you change a property:
this.CreateHistoryStep("...";
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Alexander O. Melnik 2/12/2016 1:44:00 PM
#94 Posted: 2/12/2016 12:56:48 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Alex,

Can you rotate this image by some degree [let say 30].

Jean

Rotate Image Test Alex.sm (245 KiB) downloaded 67 time(s).



Jean, image region will not rotate the image in the exposed to the user matrix manipulation way. It rotates the image using built in .NET command, and can only do it in 90 degree increments.
#95 Posted: 2/12/2016 1:02:16 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Wrote

Jean, image region will not rotate the image in the exposed to the user matrix manipulation way. It rotates the image using built in .NET command, and can only do it in 90 degree increments.



You can use the built-in RotateTransform (look at the accepted answer here); as for the context menu, can be handled like "line spacing" for WriterRegions - and if you want you can keep the old code for the existing values)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#96 Posted: 2/12/2016 1:39:35 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Wrote

Davide, is there a way to get indicate to Smath that image has changed (rotated) and workbook must be saved before closing? Right know if you rotate the image and close the workbook no prompt comes up to save the .sm file



Hello Alex,

sure, you have to implement your own HistoryStep class that extends the built-in HistoryStepBase;

Look for example the NumericUpDownRegion

- The core: NumericUpDownHistoryStep.cs

- In the region holder:
        // ...

        public override HistoryStepBase GetHistoryStep()
        {
            return new NumericUpDownHistoryStep(this);
        }

        // ...

- After you change a property:
this.CreateHistoryStep("...";



Thank you Davide, I take I should reference the .is file you provided before using this code.
#97 Posted: 2/12/2016 1:44:02 PM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

Wrote

Jean, image region will not rotate the image in the exposed to the user matrix manipulation way. It rotates the image using built in .NET command, and can only do it in 90 degree increments.



You can use the built-in RotateTransform (look at the accepted answer here); as for the context menu, can be handled like "line spacing" for WriterRegions - and if you want you can keep the old code for the existing values)




Davide, I did come across a few options on how to rotate the image by X degrees. I did, however, decide that this functionality would be outside of the scope for the goal I was trying to achieve.

The intended functionality of the rotation is to fit landscape image on a portrait page without rotating it in the editor. Everything else can be done in the editor.
#98 Posted: 2/12/2016 11:58:59 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Originally Posted by: Davide Carpi [/url]Originally Posted by: Alex.M Jean, image region will not rotate the image in the exposed to the user matrix manipulation way. It rotates the image using built in .NET command, and can only do it in 90 degree increments.

You can use the built-in RotateTransform (look at the accepted answer [url=http://stackoverflow.com/questions/14184700/how-to-rotate-image-x-degrees-in-c]here); as for the context menu, can be handled like "line spacing" for WriterRegions - and if you want you can keep the old code for the existing values)



___________________________

Thanks Alex.

I have the Smath simple coding to rotate ± 90 and -180 [mirror}
For the degree rotation the coding you give in reference is above
my competence. In lieu, I have the Mathcad bilinear working perfect
gray, RGB in Mathcad . The very last part Mathcad "on error" is problem
in Smath. I have attempted many coding, not to avail.

Attached the two sheets, the first to comfort the working code is "sanity"
Next work sheet is then in limbo.

Cheers Collabs.

Jean

Rotate Image Sanity.sm (296 KiB) downloaded 67 time(s).
Rotate Image.sm (430 KiB) downloaded 64 time(s).

#99 Posted: 2/13/2016 1:00:33 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... forgot to attach rot ± 90, -180 [mirror] & inverse grayscale

jean

Rotate Image Test Alex.sm (270 KiB) downloaded 74 time(s).
#100 Posted: 2/13/2016 3:00:18 AM
Alexander O. Melnik

Alexander O. Melnik

127 likes in 494 posts.

Group: Moderator

Wrote

... forgot to attach rot ± 90, -180 [mirror] & inverse grayscale

jean

Rotate Image Test Alex.sm (270 KiB) downloaded 74 time(s).



It is pretty impressive what you can achieve with matrix manipulations, Jean. Keep it up!
  • New Posts New Posts
  • No New Posts No New Posts