Windows Phone 8.1 如何获取存储文件的十六进制字符串

How to get Hex String of Storage File in Windows Phone 8.1

我正在使用 PhotoChooser 和 CameraCapture Taks 获取图像,

我将这些图像以 "PDF Document".

的形式存储在本地存储中

我的目的是,我必须在"Hex String"中添加这个文件。我可以将它转换成 十六进制字符串但不正确。

因为添加PDF文档后,当我在我的phone中看到该文档时,它是其他文档。

这是我的字节数组:

MemoryStream ms = new MemoryStream();
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)image1.Source);
wbitmp.SaveJpeg(ms, 400, 400, 0, 100);
bytearray = ms.ToArray();

现在,将其创建到本地存储:

StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await folder.CreateFileAsync("Test.pdf", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(sampleFile, bytearray);

然后尝试将其转换为 MemoryStream:

MemoryStream itsStream = new MemoryStream();
var outputStream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
Stream longStream = outputStream.AsStream();
longStream.CopyTo(itsStream);

byte[] allInOne = itsStream.ToArray();

这是我最终的 "PDF Document" 的 HexString:

string hexString = BitConverter.ToString(allInOne);

任何帮助将不胜感激!!

谢谢!!

终于找到方法了。我在 Windows Phone 8.1 项目中添加了 ComponentOne 库。

using C1.Phone.Pdf;
using C1.Phone.PdfViewer;

C1PdfDocument pdf = new C1PdfDocument(PaperKind.PrcEnvelopeNumber3Rotated);
pdf.Landscape = true;

var rc = new System.Windows.Rect(20,30,300,200);
pdf.DrawImage(wbitmp, rc);

var fillingName = "Test.pdf";
var gettingFile = IsolatedStorageFile.GetUserStoreForApplication();

using (var loadingFinalStream = gettingFile.CreateFile(fillingName))
{
   pdf.Save(loadingFinalStream);
   MemoryStream leadingMemoryStream = new MemoryStream();
   loadingFinalStream.Position = 0;
   loadingFinalStream.CopyTo(leadingMemoryStream);
   byte[] leadingBytes = leadingMemoryStream.ToArray();
   lastHexString = BitConverter.ToString(leadingBytes);
}