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?
Duplicate have parameters for offset, try use
origImg.Duplicate(xSize+3, 0);
corelApp.ActiveDocument.ClearSelection();
origImg.AddToSelection();
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; }