C# 位图.MakeTransparent是否适用于Windows应用商店应用?
在Winforms中,我们有一个C# 位图.MakeTransparent是否适用于Windows应用商店应用?,c#,windows-store-apps,win-universal-app,uwp,C#,Windows Store Apps,Win Universal App,Uwp,在Winforms中,我们有一个位图。MakeTransparent方法将颜色设置为透明。UWP中是否有等效的方法?(对于可写位图或软件位图等)有几种方法可以实现这一点: 首先,如果将位图用作UI控件的imagebrush,则可以根据需要设置其不透明度。下面是一个简单的演示: <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Rectangle x:Name="rct" Wid
位图。MakeTransparent
方法将颜色设置为透明。UWP中是否有等效的方法?(对于可写位图
或软件位图
等)有几种方法可以实现这一点:
首先,如果将位图用作UI控件的imagebrush,则可以根据需要设置其不透明度。下面是一个简单的演示:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Rectangle x:Name="rct" Width="800" Height="800">
<Rectangle.Fill>
<ImageBrush x:Name="ib" ImageSource="Assets//hero.bmp" Stretch="Uniform" Opacity="0.5"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
2) 获取IWICBitmap的指定矩形的一个值,然后处理现在由IWICBitmapLock对象锁定的像素数据
当然还有其他解决方案,例如使用WriteableBitmap直接操作图像像素。下面是一个使用PixelDataProvider类访问像素的示例,用于访问位图中的像素
但是,除了XAML UI元素外,Bitmap.MakeTransparent还没有简单的替代品。因此,这完全取决于您的使用模式。没有答案,而是提示:尝试使用GetPixel浏览图像,使用SetPixel为您希望自己透明的特定像素设置透明像素:(另请参见)
hr = m_pConvertedSourceBitmap->Initialize(
pFrame, // Input bitmap to convert
GUID_WICPixelFormat32bppPBGRA, // Destination pixel format
WICBitmapDitherTypeNone, // Specified dither pattern
NULL, // Specify a particular palette
0.f, // Alpha threshold
WICBitmapPaletteTypeCustom // Palette translation type
);