locked
RenderAsync does not work

    Question

  • Hi Guys,

    Below is the method that I am using to get the base 64 string from the xaml control.

       

     
     
    PrivateAsyncFunctionGetSignatureImageString(oCanvas AsBorder) AsTask(OfString)
     
     
    DimsImageData AsString= String.Empty
       
     
     
    Dimo AsNewRenderTargetBitmap
        
     
     
    'Await o.RenderAsync(oCanvas, Convert.ToInt32(oCanvas.Width), Convert.ToInt32(oCanvas.Height))
    Awaito.RenderAsync(oCanvas)
    client.Source = o
    DimaryData AsIBuffer= Awaito.GetPixelsAsync()
    IfNotaryData IsNothingThen
    sImageData = Convert.ToBase64String(aryData.ToArray())
    EndIf
    
    DimoStorageFile AsStorageFile= AwaitGUserFolder.CreateFileAsync("Client.png", CreationCollisionOption.GenerateUniqueName)
    DimoStream AsIRandomAccessStream= AwaitoStorageFile.OpenAsync(FileAccessMode.ReadWrite)
    DimoEncoder AsBitmapEncoder= AwaitBitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, oStream)
    
    oEncoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, 374, 124, DisplayInformation.GetForCurrentView.RawDpiX, DisplayInformation.GetForCurrentView.RawDpiX, aryData.ToArray())
    AwaitoEncoder.FlushAsync()
    
    oStream.Dispose()
    
     DimoBuffer AsIBuffer= AwaitFileIO.ReadBufferAsync(oStorageFile)
    
     DimaryData1 AsByte() = oBuffer.ToArray()
    ' Await oStorageFile.DeleteAsync()
    
      
    ReturnConvert.ToBase64String(aryData1)
    EndFunction
    

    Using the above function I am not getting the below result.

    Can you please help me. This occurs when I run the project in simulator

    Thanks in advance.

    Vinay


    Wednesday, September 10, 2014 7:50 AM

Answers

  • I assume that something in the height calculation or along those lines is not correct. Perhaps you should pass o.PixelHeight and o.PixelWidth into the Encoder instead of your fixed values given above. If you need those exact dimensions you'll have to render it at that size or resize it before encoding it. At least that right now is my assumption on what's going wrong here.
    • Marked as answer by PradipShinde1 Wednesday, September 17, 2014 7:59 AM
    Wednesday, September 10, 2014 3:20 PM

All replies

  • Hello,

    Is this a WPF or Windows phone project?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Wednesday, September 10, 2014 12:20 PM
  • Hello,

    This is a Windows store project.

    Thanks,

    Vinay

    Wednesday, September 10, 2014 12:26 PM
  • I am going to move this to an appropriate forum where you will get better assistance.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Wednesday, September 10, 2014 12:48 PM
  • Could you please edit your initial post in order to show the code inside a code-control so it gets readable (you get to that by pressing on the <>-Button above the text entry field next to the HTML field above the text entry box)?

    It's really hard to spot issues the way it is now.

    Wednesday, September 10, 2014 1:18 PM
  • Ok I have made the question as per your suggestion.

    Thanks,

    Vinay

    Wednesday, September 10, 2014 1:46 PM
  • Does the XAML control display correctly when you put it on a page? Is the XAML control displayed in your App or do you create it off screen (without inserting it into the Visual Tree the Layouting might not work as intended)? You could try to save the resulting PNG image to the Media Library so you can have a look at the resulting PNG which would allow us to pinpoint wether the issue is with rendering or with the encoding process following that.

    PS: Thanks for the edit - much more readable now.


    • Edited by Oliver Ulm Wednesday, September 10, 2014 1:56 PM
    Wednesday, September 10, 2014 1:56 PM
  • Hi,

    When I put the Image control into the xaml and set source using rendertargetbitmap it shows correctly.

    But When I get the pixel data using GetPixelsAsync(), it gives incorrect data.

    Thanks,

    Vinay

    Wednesday, September 10, 2014 3:01 PM
  • I assume that something in the height calculation or along those lines is not correct. Perhaps you should pass o.PixelHeight and o.PixelWidth into the Encoder instead of your fixed values given above. If you need those exact dimensions you'll have to render it at that size or resize it before encoding it. At least that right now is my assumption on what's going wrong here.
    • Marked as answer by PradipShinde1 Wednesday, September 17, 2014 7:59 AM
    Wednesday, September 10, 2014 3:20 PM
  • Thanks Seems I solved the problem.
    Wednesday, September 17, 2014 7:59 AM