How i can after i create a duplicate move back the selection to the orig shape.So that this Original image always is selected?
In my case is it so:
i select a picture and create a duplicate on the right side. But after this is the duplicate selected. I would like that is only the origin Image is selected
1 2 3 4 5 6 7 8 9 10
private void Button_Click(object sender, RoutedEventArgs e) { corelApp.ActiveDocument.Unit = corelApp.ActiveDocument.Rulers.HUnits; corelApp.ActiveSelection.Shapes.All().CreateSelection(); xSize = corelApp.ActiveSelection.SizeWidth; origImg = corelApp.ActiveSelectionRange.FirstShape; origImg.Duplicate(); corelApp.ActiveSelection.Move(xSize+3, 0); //ConvertImage(); }
No need to select. Please, use the next suggestion:
origImg.Duplicate();
origImg.Move(xSize+3, 0);
The result is the same. Maybe i need to give the copy a name?
it gives an error who i not understand "Reference object no longer available"This error comes after i move the slider second time. Also when i press on the side by the knob
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
private corel.Shape origImg; private corel.Shape dplS; private int globalVar = 0; private int imgResolution; private void DuplicateMove(int sldValue) { if (origImg == null) // working for the first time. Setting the shapes included { origImg = corelApp.ActiveLayer.Shapes.All().FirstShape; dplS = origImg.Duplicate(); dplS.LeftX = (origImg.LeftX - origImg.SizeWidth - 1); } else //working after the shapes have been set { dplS.Delete(); dplS = origImg.Duplicate(); dplS.LeftX = (origImg.LeftX - origImg.SizeWidth - 1); } //set the resolution to the dplS shape, using sldValue dplS = corelApp.ActiveSelection.ConvertToBitmapEx(corel.cdrImageType.cdrGrayscaleImage, false, false, sldValue, corel.cdrAntiAliasingType.cdrNormalAntiAliasing, false, true, 95); } private void ImageSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { if (corelApp != null) // only when a selection is activated { var slider = sender as Slider; // ... Get Value. DuplicateMove(System.Convert.ToInt32(slider.Value)); } } private void BtnImageResultOK(object sender, RoutedEventArgs e) { double Lx; Lx = origImg.LeftX; origImg.Delete(); dplS.LeftX = Lx; }
Does the code run once? If yes, we must understand why the shape does not keep the object preliminary set. I would firstly try 'public corel.Shape origImg;' and do the same with the other shape declaration.
I would suggest you to try the code in VBA. Using a 'SpinButton' instead of slider. If it works as you need, you only must better focus on the code conversion. The code works as (I understand) you need...
Ok now i createt the +/- picker. So we can see where is the problem. This is much better as the slider for debugging. The errors are "Reference object no longer available"
The first value change on picker works OK, but the origin image is not selected anymore.If i press the OK button it comes aslo the same warningIt is about the object was not longer avaiable. Maybe the system "windows" delete the object to save memory?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
private corel.Shape origImg; private corel.Shape dplS; private int globalVar = 0; private int imgResolution = 250; private void DuplicateMove(int sldValue) { corelApp.ActiveDocument.Unit = corelApp.ActiveDocument.Rulers.HUnits; if (origImg == null) // working for the first time. Setting the shapes included { origImg = corelApp.ActiveLayer.Shapes.All().FirstShape; dplS = origImg.Duplicate(); dplS.LeftX = (origImg.LeftX - origImg.SizeWidth - 1); } else //working after the shapes have been set { dplS.Delete(); dplS = origImg.Duplicate(); dplS.LeftX = (origImg.LeftX - origImg.SizeWidth - 1); } //set the resolution to the dplS shape, using sldValue dplS = corelApp.ActiveSelection.ConvertToBitmapEx(corel.cdrImageType.cdrGrayscaleImage, false, false, sldValue, corel.cdrAntiAliasingType.cdrNormalAntiAliasing, false, true, 95); } private void BtnImageResultOK(object sender, RoutedEventArgs e) { double Lx; Lx = origImg.LeftX; origImg.Delete(); origImg = null; dplS.LeftX = Lx; } private void Button_Click_Minus(object sender, RoutedEventArgs e) { imgResolution--; TxbImageDPI.Text = imgResolution.ToString(); if (corelApp.ActiveSelection.Shapes.Count != 0) // only when a selection is activated { DuplicateMove(imgResolution); } } private void Button_Clic_Plus(object sender, RoutedEventArgs e) { imgResolution++; TxbImageDPI.Text = imgResolution.ToString(); if (corelApp.ActiveSelection.Shapes.Count != 0) // only when a selection is activated { DuplicateMove(imgResolution); } }
The problem is the copy is allways the same as the original. this means that when a change is made to the copy, it also changes the original. Is this only a C# problem?
docs.microsoft.com/.../system.object.memberwiseclone
I do not think so... I played with 'Duplicate' many times (in VBA), not changing the resolution, but using shapes and modifying the shape fill color, dimensions etc. The original shape being duplicated was not affected. And it cannot be related to C# strictly. It uses the same methods as VBA, from the same `Application` main class. Let me look a little at your code...
I think 'dplS = corelApp.ActiveSelection.ConvertToBitmapEx...' is inappropriate...
Please, try using `dplS = dplS.ConvertToBitmapEx...' Otherwise, the real duplicated picture is replaced with the `ActiveSelection` converted to Bitmap...
I adapted my above VBA proposed code (except the code format...) to see how I used the duplicated object when played with its resolution and it works as expected. I only suppose that my expectations are similar with yours...:)
Hi FaneDuru. Many thanks....Your solution works perfectly
FaneDuru said:Please, try using `dplS = dplS.ConvertToBitmapEx
Now i have learned a lot about the whole thing.Best regards -Remo
Glad I could help...