Home
MatriX vNext
MatriX XMPP SDK ▼
Forum
About us ▼
Contact
Not logged in.
·
Lost password
·
Register
Forum
Search
Members
Forum:
MatriX and XmppDotNet
Convert BitmapImage to byte[] or stream in WinRT
goodzhengcheng
2013-04-29, 14:03
#1
Member since Mar 2013 ·
8
posts
Group memberships:
Members
Show profile
·
Link to this post
Subject:
Convert BitmapImage to byte[] or stream in WinRT
Because the type of Vcard.Photo.Binval is byte[], So I must convert BitmapImage to byte[] or stream in WinRT. Who can help me?
Alex
2013-04-29, 14:25
#2
Member since Feb 2003 ·
4449
posts · Location: Germany
Group memberships:
Administrators, Members
Show profile
·
Link to this post
I use this code in some of our WPF projects. Have not tested it on WinRT yet. Does it work for you?
public
static
Byte
[
]
ByteBufferFromImage
(
BitmapImage imageSource
)
{
var
ms
=
new
MemoryStream
(
)
;
var
pngEncoder
=
new
PngBitmapEncoder
(
)
;
pngEncoder
.
Frames
.
Add
(
BitmapFrame
.
Create
(
imageSource
)
)
;
pngEncoder
.
Save
(
ms
)
;
return
ms
.
GetBuffer
(
)
;
}
public
static
BitmapImage ImageFromBuffer
(
Byte
[
]
bytes
)
{
var
stream
=
new
MemoryStream
(
bytes
)
;
var
image
=
new
BitmapImage
(
)
;
image
.
BeginInit
(
)
;
image
.
StreamSource
=
stream
;
image
.
EndInit
(
)
;
return
image
;
}
goodzhengcheng
2013-04-29, 14:29
#3
Member since Mar 2013 ·
8
posts
Group memberships:
Members
Show profile
·
Link to this post
It seems does not work,there is no PngBitmapEncoder class in WinRT,and there is no Create method in BitmapFrame class.
Close
Smaller –
Larger +
Reply to this post:
Verification code:
Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys:
Special characters:
Forum:
MatriX and XmppDotNet