sonia
sonia

Reputation: 13

how to merge two images in windows phone and save it to isolated storage

I want to merge two images,one image is of 300x300 and other is 100x100, First i have created a canvas and then i created two images which i have added to the both the images to canvas and the canvas is added to the content panel, then i created a writeablebitmap and render the canvas and created a method savejpeg which saves the image to isolated stoarage,but isolated storage is not showing the whole image it save a black screen.

First i created a canvas through code set its height width and background color then i created two images programmatically which i have added to the canvas and then canvas is added to the contentpanel

my code is:

   public void CreateImage()
    {

        Canvas canvas = new Canvas();
        canvas.Height = 400;
        canvas.Width = 400;
        canvas.Background = new SolidColorBrush(Colors.Red);

        Image img1 = new Image();
        img1.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("Image/Desert.jpg");
        img1.Height = 300;
        img1.Width = 300;
        img1.Margin = new Thickness(0, 10, 0, 0);

        Image img2 = new Image();
        img2.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("Image/Jellyfish.jpg");
        img2.Height = 50;
        img2.Width = 50;
        img2.Margin=new Thickness(0,10,300,0);


        canvas.Children.Add(img1);
        canvas.Children.Add(img2);
        ContentPanel.Children.Add(canvas);

        WriteableBitmap wb = new WriteableBitmap(400, 400);
        wb.Render(canvas, new MatrixTransform());
        MemoryStream ms = new MemoryStream();


        wb.SaveJpeg(ms,400,400,0,100);

        using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication()))
        {
            wb.SaveJpeg(isoFileStream, 400, 400, 0, 100);
        }

    }

When i save the image then i am getting a black screen in isolated storage. How to save both images on canvas?

Upvotes: 0

Views: 1119

Answers (2)

Rakesh R Nair
Rakesh R Nair

Reputation: 1785

Like Stephan said, I think you are not getting the image to your source. Any way I created a sample application for you. In that you can find two partitions, you can add image to that by double tapping on the container. After that try save and check your saved image. I tested the app and every thing is working for me. Still you face any kind of issues please leave a comment.

https://www.dropbox.com/s/1vjbbou96w0r15r/SaveImageApp.zip

Upvotes: 3

Stephan Ronald
Stephan Ronald

Reputation: 1405

Please check weather you are getting image or not to image source. If you are getting the image; try this method to take snapshot from control and save that to Iso store.

 http://stackoverflow.com/questions/13837148/how-can-i-take-a-screenshot-full/13990649#13990649

Upvotes: 0

Related Questions