Add method to convert wxDIB to wxImage enforcing alpha channel values (wxMSW).
wxDIB::ConvertToImage called with Convert_AlphaAuto converts wxDIB to wxImage with automatic checking if 32 bpp DIB contains real alpha values (legacy way). When it is called with Convert_AlphaAlwaysIf32bpp then automatic checking is disabled and 32 bpp DIB is unconditionally converted to ARGB wxImage.
This commit is contained in:
@@ -164,7 +164,18 @@ public:
|
|||||||
bool Create(const wxImage& image, PixelFormat pf = PixelFormat_PreMultiplied);
|
bool Create(const wxImage& image, PixelFormat pf = PixelFormat_PreMultiplied);
|
||||||
|
|
||||||
// create wxImage having the same data as this DIB
|
// create wxImage having the same data as this DIB
|
||||||
wxImage ConvertToImage() const;
|
|
||||||
|
// Possible options of conversion to wxImage
|
||||||
|
enum ConversionFlags
|
||||||
|
{
|
||||||
|
// Determine whether 32bpp DIB contains real alpha channel
|
||||||
|
// and return wxImage with or without alpha channel values.
|
||||||
|
Convert_AlphaAuto,
|
||||||
|
// Assume that 32bpp DIB contains valid alpha channel and always
|
||||||
|
// return wxImage with alpha channel values in this case.
|
||||||
|
Convert_AlphaAlwaysIf32bpp
|
||||||
|
};
|
||||||
|
wxImage ConvertToImage(ConversionFlags flags = Convert_AlphaAuto) const;
|
||||||
#endif // wxUSE_IMAGE
|
#endif // wxUSE_IMAGE
|
||||||
|
|
||||||
|
|
||||||
|
@@ -676,7 +676,7 @@ bool wxDIB::Create(const wxImage& image, PixelFormat pf)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImage wxDIB::ConvertToImage() const
|
wxImage wxDIB::ConvertToImage(ConversionFlags flags) const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxNullImage,
|
wxCHECK_MSG( IsOk(), wxNullImage,
|
||||||
wxT("can't convert invalid DIB to wxImage") );
|
wxT("can't convert invalid DIB to wxImage") );
|
||||||
@@ -776,7 +776,7 @@ wxImage wxDIB::ConvertToImage() const
|
|||||||
if ( hasOpaque && hasTransparent )
|
if ( hasOpaque && hasTransparent )
|
||||||
hasAlpha = true;
|
hasAlpha = true;
|
||||||
|
|
||||||
if ( !hasAlpha && image.HasAlpha() )
|
if ( !hasAlpha && image.HasAlpha() && flags == Convert_AlphaAuto )
|
||||||
image.ClearAlpha();
|
image.ClearAlpha();
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
Reference in New Issue
Block a user