Editable Image Region

Editable Image Region - Сообщения

#81 Опубликовано: 09.02.2016 02:14:50
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 09.02.2016 03:45:10
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 КиБ) скачан 56 раз(а).
#83 Опубликовано: 09.02.2016 05:04:01
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 Опубликовано: 09.02.2016 05:12:10
Вячеслав Мезенцев

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

1402 сообщений из 1708 понравились пользователям.

Группа: 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 пользователям понравился этот пост
Davide Carpi 09.02.2016 06:15:00, Alexander O. Melnik 09.02.2016 13:51:00
#85 Опубликовано: 10.02.2016 02:58:30
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 10.02.2016 03:00:52
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 КиБ) скачан 49 раз(а).
1 пользователям понравился этот пост
Davide Carpi 10.02.2016 19:38:00
#87 Опубликовано: 10.02.2016 19:36:25
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 Опубликовано: 10.02.2016 20:35:41
kilele

kilele

133 сообщений из 397 понравились пользователям.

Группа: 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 Опубликовано: 10.02.2016 23:54:03
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 10.02.2016 23:59:09
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 КиБ) скачан 49 раз(а).
1 пользователям понравился этот пост
Davide Carpi 11.02.2016 05:39:00
#91 Опубликовано: 12.02.2016 00:30:28
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 12.02.2016 01:00:02
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Alex,

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

Jean

Rotate Image Test Alex.sm (245 КиБ) скачан 56 раз(а).
1 пользователям понравился этот пост
Alexander O. Melnik 12.02.2016 13:45:00
#93 Опубликовано: 12.02.2016 04:52:46
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 пользователям понравился этот пост
Alexander O. Melnik 12.02.2016 13:44:00
#94 Опубликовано: 12.02.2016 12:56:48
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

Alex,

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

Jean

Rotate Image Test Alex.sm (245 КиБ) скачан 56 раз(а).



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 Опубликовано: 12.02.2016 13:02:16
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 Опубликовано: 12.02.2016 13:39:35
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 12.02.2016 13:44:02
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: 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 Опубликовано: 12.02.2016 23:58:59
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 КиБ) скачан 56 раз(а).
Rotate Image.sm (430 КиБ) скачан 56 раз(а).

#99 Опубликовано: 13.02.2016 01:00:33
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

jean

Rotate Image Test Alex.sm (270 КиБ) скачан 63 раз(а).
#100 Опубликовано: 13.02.2016 03:00:18
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

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

jean

Rotate Image Test Alex.sm (270 КиБ) скачан 63 раз(а).



It is pretty impressive what you can achieve with matrix manipulations, Jean. Keep it up!
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений