Hi all of you,
My aim is once my user has selected one area of one JPG file, that piece is going to move into one container, e.g, a GroupBox.
As you will see in the following image, left headlight of the car has been selected in green one and from that context menu, user could move that section into a GroupBox on the right:
Code-behind stuff:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) GuardarCanvas(FaroDelantero, 96, "c:\puesto\test.png") End Sub Public Function GuardarCanvas(cnvSeleccionado As Canvas, dpi As Integer, fArchivo As String) As Boolean Dim tamaño As Size = New Size(cnvSeleccionado.Width, cnvSeleccionado.Height) Dim pixels(cnvSeleccionado.Height * cnvSeleccionado.Width) As Byte Dim Paleta As BitmapPalette = BitmapPalettes.Halftone256 cnvSeleccionado.Measure(tamaño) Dim bmp As New RenderTargetBitmap(cnvSeleccionado.Width, cnvSeleccionado.Height, _ dpi, dpi, PixelFormats.Pbgra32) bmp.Render(cnvSeleccionado) Dim enc As New System.Windows.Media.Imaging.PngBitmapEncoder Dim image As BitmapSource = System.Windows.Media.Imaging.BitmapImage.Create(cnvSeleccionado.Width, cnvSeleccionado.Height, dpi, dpi, _ PixelFormats.Indexed8, Paleta, pixels, cnvSeleccionado.Width) Dim stream As New FileStream(fArchivo, FileMode.Create) enc.Save(stream) End FunctionError on Save method: Cannot save an image with no frames.
XAML for that Canvas (path captured from Blend):
<Canvas x:Name="FaroDelantero" Height="448" Width="640" Canvas.Left="-85" Canvas.Top="-80" ><Path Data="M209.43344,292.90402 C197.89236,296.62282 186.71025,300.54841 174.75851,303.3065 162.12502,306.22192 149.49235,316.26562 138.0031,318.56347 136.39685,328.20095 122.05263,337.14247 122.05263,346.30341 132.64681,341.00632 153.74403,347.6904 167.82353,347.6904 171.75335,347.6904 175.68318,347.6904 179.613,347.6904 184.95751,347.6904 185.28559,347.54504 189.32198,342.83591 194.97734,336.23799 193.26098,333.72613 203.19195,331.73994 203.19195,331.27761 203.19195,330.81527
203.19195,330.35294 213.61361,326.87905 223.51361,321.94452 232.31889,315.09598 238.63053,310.18692 249.14523,297.66732 255.89783,294.29102 260.28935,292.09526 266.06131,288.41168 248.96285,285.96904 241.3395,284.87999 235.9299,289.53218 228.15789,290.13003 221.76274,290.62197 215.83859,292.21053 208.73994,292.21053 199.07388,292.21053 197.31319,295.501 189.32198,300.53251" Height="61.885" Canvas.Left="122.053" Stretch="Fill" Canvas.Top="285.805" Width="138.442"><Path.Fill><ImageBrush/></Path.Fill></Path></Canvas>
Thanks a lot for your thoughts,
Primary platform is Windows 7 Ultimate 64 bit along with VS 2012/Sql2k8 for WPF/SilverLight projects.