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?
What do you like moving? Not the first shape of the initial selection? If yes, I cannot see how it does not work in the way I suggested... If not, please better explain what your code tries moving. Do you need moving the duplication resulted shape?
I think it is better if I try to explain exactly what I want to do. So i do it in corel without a macro.
1. select an image
2. then the image right next to it is duplicated with the edit mode button.
3. then i can change the resolution with a slider from 100-500dpi
4. i want the new created image to be always on the left side of the original place. and the original is now on the right side as unchanged reference. I think we need also on every slider value changed to delete the left picture and start again the image conversation.
5. when i am satisfied with the set resolution, i press the OK button and the unchanged original reference image on the right side is deleted. So that only the changed image is still in the original place with the new resolution
I think it is a matter of variables to be declared and two methods to deal in order to obtain what you need.
I do not have C# installed on my new laptop and I will try showing a VBA scenario, which should be easily converted:
1. Declare two variable of the class level (module level in VBA):
1
Private origImg As Shape, dplS As Shape
2. Use the next two methods (Subs in VBA). The first one will be called by the slider change event, passing the slider value as argument:
1 2 3 4 5 6 7 8 9 10 11 12 13
Sub DuplicateMove(sldValue As Double) If origImg Is Nothing Then 'working for the first time. Setting the shapes included Set origImg = ActiveLayer.Shapes.All.FirstShape Set dplS = origImg.Duplicate dplS.LeftX = origImg.LeftX + origImg.SizeWidth + 1 Else 'working after the shapes have been set. dplS.Delete Set dplS = origImg.Duplicate dplS.LeftX = origImg.LeftX + origImg.SizeWidth + 1 End If 'set the resolution to the dplS shape, using sldValue Set dplS = dplS.ConvertToBitmapEx(cdrGrayscaleImage, False, False, sldValue, cdrNormalAntiAliasing, False, True, 95) End Sub
1 2 3 4 5 6
Sub testOK() Dim Lx As Double Lx = origImg.LeftX origImg.Delete : Set origImg = Nothing dplS.LeftX = Lx End Sub
If the slider increment is too small, it can be used only for fine tuning. It can change a value of a text box and the method to be triggered by its event. In this way, you may manually change the text box value and only pressing Enter, it will do the job...
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...:)