Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Text on Image
    primarykey
    data
    text
    <p>I am trying to add some text on top of a photo take by the camera, and here is the method I am using, but unfortunately I either get a closedStream error, or that there is cross-thread access when I try use the dispatcher. Could someone please explain me what is going wrong?</p> <pre><code> void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e) { DateTime dt = DateTime.Now; string fileName = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + ".jpg"; try { // Save picture to the library camera roll. library.SavePictureToCameraRoll(fileName, e.ImageStream); // Set the position of the stream back to start e.ImageStream.Seek(0, SeekOrigin.Begin); Deployment.Current.Dispatcher.BeginInvoke(() =&gt; { // load photo to writable bitmap WriteableBitmap writeableBitmap = PictureDecoder.DecodeJpeg(e.ImageStream); writeableBitmap.Invalidate(); var renderText = new TextBlock { Text = "Hello World", FontSize = 72, Foreground = new SolidColorBrush(Colors.White), FontWeight = FontWeights.Black, Width = 500, Height = 100 }; writeableBitmap.Render(renderText, new TranslateTransform() { X = 100, Y = 300 }); writeableBitmap.Invalidate(); using (var ms = new MemoryStream()) { writeableBitmap.SaveJpeg(ms, 1024, 768, 0, 100); ms.Seek(0, SeekOrigin.Begin); library.SavePicture("x" + fileName, ms); } // e.ImageStream.Close(); }); // Save picture as JPEG to isolated storage. using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write)) { // Initialize the buffer for 4KB disk pages. byte[] readBuffer = new byte[4096]; int bytesRead = -1; // Copy the image to isolated storage. while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) &gt; 0) { targetStream.Write(readBuffer, 0, bytesRead); } } } } finally { // Close image stream e.ImageStream.Close(); } } </code></pre> <p>With the code above I get the following error: Cannot access a closed Stream.</p> <p>If i remove the Dispatcher, I get this error: Invalid cross-thread access.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload