Question

I have a class that uses the devices camera to capture an image. My aim is to pass the captured image to a canvas on another layout.

This layout will then be saved along with a note entered into a textbox.I have figured out how to save the note and title and allow it to be opened but I'm not sure how I would go about passing the captured image to the layout and saving it along with the note.

Does anyone have any advice or pointers as to how I would go about this?

At the moment this is how I'm attempting to read the image file back to the layout after it is saved,but I'm not sure how to read a file into the canvas so obviously this solution isn't working yet:

if (NavigationContext.QueryString.ContainsKey("note")) 
            { 
                string s2 = ".jpg";

                string filename = this.NavigationContext.QueryString["note"]; 
                if (!string.IsNullOrEmpty(filename)) {
                    using (var store = System.IO.IsolatedStorage.IsolatedStorageFile .GetUserStoreForApplication()) 
                    using (var stream = new IsolatedStorageFileStream(filename, FileMode.Open, FileAccess.ReadWrite, store))


                    /*
                    if(filename.Contains(s2))
                    {
                        StreamReader reader = new StreamReader(stream);
                        this.capturedNoteCanvas = reader.ReadToEnd();
                        this.noteNameTb.Text = filename; reader.Close();
                    }
                    else
                     */
                    { 
                        StreamReader reader = new StreamReader(stream); 
                        this.noteDataTb.Text = reader.ReadToEnd(); 
                        this.noteNameTb.Text = filename; reader.Close(); 
                    }
                }
            } 

What I'm thinking is something like this:

Proposed UI

Was it helpful?

Solution

Working wit CameraCaptureTask and Bitmaps

//Taking a writableBitmap object from cameracapturetask

void cameracapturetask_Completed(object sender, PhotoResult e)
        {
            try
            {
                if (e.TaskResult == TaskResult.OK)
                {
                    BitmapImage bmp = new BitmapImage();
                    bmp.SetSource(e.ChosenPhoto);
                    WritableBitmap wb=new WritableBitmap (bmp.PixelWidth,bmp.PixelHeight);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

saving wb in storage

                            using (MemoryStream stream = new MemoryStream())
                            {
                                wb.SaveJpeg(stream, (int)bmp.PixelWidth, (int)bmp.PixelHeight, 0, 100);
                                using (IsolatedStorageFileStream local = new IsolatedStorageFileStream(App.PageName, FileMode.Create, mystorage))
                                {
                                    local.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
                                }
                            }

//Taking a WritableBitmap from canvas

If your canvas is containing the image, and also the canvas it attributed with some height and width properties then

WritableBitmap wb= new WritableBitmap(canvascontrol,null);

takes the canvas and saves it inside a writablebitmap object which can then be used for further image manipulations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top