Convert 0RGB wxBitmaps to RGB when copying them to clipboard

Not all applications recognize properly 0RGB bitmap format so for the sake
of interoperability bitmaps in such format should be converted to plain
24 bpp RGB format prior to being copied to the clipboard.

Closes #17640.
This commit is contained in:
Artur Wieczorek
2017-04-30 21:35:01 +02:00
parent 063681162a
commit b1fad4da44
2 changed files with 22 additions and 3 deletions

View File

@@ -636,6 +636,26 @@ bool wxClipboard::AddData( wxDataObject *data )
wxCHECK_MSG( data, false, wxT("data is invalid") );
const wxDataFormat format = data->GetPreferredFormat();
if ( format == wxDF_BITMAP || format == wxDF_DIB )
{
wxBitmapDataObject* bmpData = (wxBitmapDataObject*)data;
wxBitmap bmp = bmpData->GetBitmap();
wxASSERT_MSG( bmp.IsOk(), wxS("Invalid bitmap") );
// Replace 0RGB bitmap with its RGB copy
// to ensure compatibility with applications
// not recognizing bitmaps in 0RGB format.
if ( bmp.GetDepth() == 32 && !bmp.HasAlpha() )
{
wxBitmap bmpRGB(bmp.GetSize(), 24);
wxMemoryDC dc(bmpRGB);
dc.DrawBitmap(bmp, 0, 0);
dc.SelectObject(wxNullBitmap);
bmpData->SetBitmap(bmpRGB);
}
}
#if wxUSE_OLE_CLIPBOARD
HRESULT hr = OleSetClipboard(data->GetInterface());
if ( FAILED(hr) )
@@ -664,8 +684,6 @@ bool wxClipboard::AddData( wxDataObject *data )
#elif wxUSE_DATAOBJ
wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") );
wxDataFormat format = data->GetPreferredFormat();
switch ( format )
{
case wxDF_TEXT:
@@ -681,7 +699,7 @@ bool wxClipboard::AddData( wxDataObject *data )
{
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
wxBitmap bitmap(bitmapDataObject->GetBitmap());
return wxSetClipboardData(data->GetPreferredFormat(), &bitmap);
return wxSetClipboardData(format, &bitmap);
}
#if wxUSE_METAFILE