GetPixelDataAsync ignores parameter


  • Hi,

    I'm trying to load a Bitmap image using BitmapDecoder. The Bitmap contains alpha values, it is created by the app itself using

    	BitmapAlphaMode::Straight, _icon->PixelWidth,
    	_icon->PixelHeight, 96.0, 96.0, ref new Array<byte>
    	(pixels, _icon->PixelWidth * _icon->PixelHeight * 4));

    When I open the resulting image with Paint.net, the alpha channel is correctly displayed.

    Now I try to open it using the following code:

    return task<StorageFile^>( ApplicationData::Current->LocalFolder->GetFileAsync(accessID) ).then([](StorageFile ^file) { return task<IRandomAccessStream^>(file->OpenAsync(FileAccessMode::ReadWrite)); }).then([this, decoder](IRandomAccessStream ^stream) -> IAsyncOperation<BitmapDecoder^>^ { return BitmapDecoder::CreateAsync(BitmapDecoder::BmpDecoderId, stream); }).then([this, decoder](BitmapDecoder^ createdDecoder) -> IAsyncOperation<PixelDataProvider^>^ { *decoder = createdDecoder;

    //Problem somewhere here return (*decoder)->GetPixelDataAsync(BitmapPixelFormat::Rgba8, BitmapAlphaMode::Straight, ref new BitmapTransform(), ExifOrientationMode::IgnoreExifOrientation, ColorManagementMode::DoNotColorManage); }).then([this, decoder](task<PixelDataProvider^> t) -> void { PixelDataProvider ^data; try{ data = t.get(); } catch (Exception ^e){ _icon = nullptr; return; } _icon = ref new WriteableBitmap((*decoder)->PixelWidth, (*decoder)->PixelHeight); ComPtr<IInspectable> bufferInspectable(reinterpret_cast<IInspectable*>(_icon->PixelBuffer)); ComPtr<IBufferByteAccess> bufferBytes; bufferInspectable.As(&bufferBytes); byte* pixels; bufferBytes->Buffer(&pixels); Array<byte> ^src = data->DetachPixelData(); memcpy(pixels, src->Data, src->Length); });

    Everything works fine, except the alpha channel is simply ignored. If I use GetPixelDataAsync without any Parameters, the result is the same. Seems this method is somehow ignoring it's Parameters?!

    Greetings Liechtenschwein

    Saturday, October 25, 2014 7:00 PM

All replies

  • To load the decoded bitmap in a WriteableBitmap decode as Bgra8 and Premultiplied alpha
    Saturday, October 25, 2014 9:58 PM
  • Thanks for the quick response, and sorry for the late reaction.

    Unfortunately, that doesn't change anything, the alpha channel is still ignored :(

    Wednesday, November 19, 2014 8:17 PM
  • What happens if you create the bitmap with premultiplied alpha?

    Can you share a minimal project which demonstrates the problem?

    Friday, November 21, 2014 1:15 AM
  • Hope you can use this: https://onedrive.live.com/redir?resid=B9392B696B84062E!38860&authkey=!AL_bUWeMPct_FSo&ithint=folder%2c

    Monday, December 01, 2014 4:18 PM