Convert byte Array or File Storage to Bitmap Image

后端 未结 1 1394
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 19:45

After I pick file to storage file , How can I convert this file to be שn image in order to display it like profile picture?
I converted the file to byte array but don\'t kno

1条回答
  •  北海茫月
    2021-01-27 20:24

    Below code converts bytes into BitmapImage

    BitmapImage image1 = new BitmapImage();
    InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
    ms.WriteAsync(tBytes.AsBuffer());
    ms.FlushAsync().AsTask().Wait();
    ms.Seek(0);
    image1.SetSource(ms);
    image.Source = image1;
    


    I got this from somewhere, Try this if it helps

    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.FileTypeFilter.Add(".jpg");
    openPicker.FileTypeFilter.Add(".cmp");
    openPicker.FileTypeFilter.Add(".png");
    openPicker.FileTypeFilter.Add(".tif");
    openPicker.FileTypeFilter.Add(".gif");
    openPicker.FileTypeFilter.Add(".bmp");
    StorageFile file = await openPicker.PickSingleFileAsync();
    IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
    BitmapImage bmp = new BitmapImage();
    bmp.SetSource(stream);
    Image1.Source = bmp;
    

    0 讨论(0)
提交回复
热议问题