locked
How can I implement BitmapImage.CopyPixels func in Metro APP?

    Question

  • Hi,all

    I have one MemoryStream object and can covert to BitmapImage, and I need copy pixel to one byte[] object,

    but in metro app, BitmapImage class did not have this func, How can I implement this fuc in Metro APP?


    Monday, March 24, 2014 8:21 AM

All replies

  • Perhaps I'm missing something, but I don't know why you'd convert first from MemoryStream to BitmpaImage, then copy the pixels to a byte array. Can you go straight to byte app array using MemoryStream.ToArray?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, March 24, 2014 7:15 PM
    Moderator
  • I test it, but MemoryStream.ToArray is diff with use CopyPixels byte[].
    • Edited by Maxlovexxx Wednesday, March 26, 2014 8:16 AM
    Wednesday, March 26, 2014 8:16 AM
  • How is it different?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, March 26, 2014 12:35 PM
    Moderator
  • I Debug to test it,it different。I did not know why。
    Wednesday, April 02, 2014 6:29 AM
  • Try writing the bytes to file doing it both ways, post links to the text file, and I'll investigate.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, April 03, 2014 2:09 PM
    Moderator
  • If you need to extract the pixels from an image use a WriteableBitmap instead of a BitmapImage. They are both ImageSources and can be used interchangeably in most cases.

    As Matt says though, if you already have the bytes in your stream you should be able to skip the step unless you're doing a conversion in he middle. Are the bytes in your stream raw pixels or are they an encoded format (JPG, png, etc.?) If you need to decode from an image file format to raw pixels you can use a BitmapDecoder.

    Can you show your code as well as the resulting files Matt asked for?

    Thursday, April 03, 2014 2:18 PM
    Owner