Fixed the palette issue, and by adding channels=>4 to the Imager constructor it all looks much nicer.
Final proof of concept code:
# Get its icon image
my $WM_ICON = $xtops->{_NET_WM_ICON};
{
my ($value,$type,$format,$bytes_after) = $X->GetProperty($id, $WM_ICON...