Cannot get Uri for an in-memory object because of missing PackageStore class

50 Views Asked by At

I need to get the URI of an in-memory bitmap because the class I want to use accepts only bitmap URIs, not byte[] data. Also, I don't want to create temporary files for this purpose but operate only with the memory. In .NET Framework I can do this:

Uri GetMemoryBitmapUri()
{
    MemoryStream packStream = new MemoryStream();
    Package pack = Package.Open(packStream, FileMode.Create, FileAccess.ReadWrite);
    Uri packUri = new Uri("packUri:");
    PackageStore.AddPackage(packUri, pack);  // we don't have PackageStore in .NET
    Uri packPartUri = new Uri("/bitmap.jpg", UriKind.Relative);
    PackagePart packPart = pack.CreatePart(packPartUri, System.Net.Mime.MediaTypeNames.Image.Jpeg);
    var bitmapBytes = GetInMemoryBitmapData();
    packPart.GetStream().Write(bitmapBytes, 0, bitmapBytes.Length);
    return PackUriHelper.Create(packUri, packPart.Uri);
}

And it works - the reference returned from GetMemoryBitmapUri() can be passed to the method of the class I would like to use and the bitmap is drawn.

But I have a problem when trying to do this in .NET 7 since there is no longer PackageStore class in System.IO.Packaging and so I cannot make PackageStore.AddPackage call. How can I handle this problem?

0

There are 0 best solutions below