Editable Image Region - Messages
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
Ughh... So now if I click on one of the menu items, it remembers my section for the next blank region I insert. Bummer
Still cannot make checkmarks for context menu items work.
ImageRegion.009.zip (74 KiB) downloaded 66 time(s).
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;
}
WroteThe 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
WroteAlso 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
WroteAlex, 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..
ImageRegion.011.zip (78 KiB) downloaded 59 time(s).

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();
}
// ...
}

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.
WroteHi 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.
WroteNice
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).
Can you rotate this image by some degree [let say 30].
Jean
Rotate Image Test Alex.sm (245 KiB) downloaded 67 time(s).
WroteDavide, 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("..."
;
WroteAlex,
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.
WroteJean, 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)
WroteWroteDavide, 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.
WroteWroteJean, 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.
WroteOriginally 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).
jean
Rotate Image Test Alex.sm (270 KiB) downloaded 74 time(s).
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
-
No New Posts