簡體   English   中英

在Windows Phone應用程序中將位圖更改為不同的形狀

[英]Change Bitmap to different shapes in Windows Phone app

我一直在尋找解決方案一段時間,但還沒有找到它。 我的應用程序的一個功能是加載圖像,然后更改其形狀 - 例如,我加載一個普通的矩形圖像,然后有2-3個按鈕 - 將圖像更改為圓形,三角形或其他形狀。 是這樣甚至可能與Bitmaps? 我發現諾基亞成像SDK有很多有趣的東西,但我發現的所有形狀都是LensBlurEffect ,這不是我需要的。

如果有人能指出我正確的方向,我將非常感激!

提前感謝您的幫助!

最好的問候,羅馬

那么位圖總是長方形的,你無能為力。

您可以做的是使一些像素透明,從而使位圖看起來具有不同的形狀。

使用諾基亞成像SDK的一種方法是使用BlendFilter在原始圖像上混合透明圖像(我建議只使用ColorImageSource)。 您可以提供不同的蒙版來創建不同的“形狀”。

我正在研究使用諾基亞成像SDK繪制形狀的濾鏡。 為了解決您的問題,我創建了使用Nokia Imaging SDK的混合濾鏡和自定義形狀濾鏡的示例項目。

實際上你可以像大衛所說的那樣對形狀圖像做同樣的事情(背景為黑色,前景為白色)而不是使用我的自定義濾鏡(上面的示例代碼為EllipseShapeFilter)。

這是示例代碼;

var ellipseImage = new WriteableBitmap(1024, 768);
Rect origin = new Rect(new Point(512, 384), new Size(512, 384));
uint white = 0xff000000 | (255 << 16) | (255 << 8) | 255;

var image = LoadFromResources(new Uri(@"/BlendImageSample;component/Assets/Sample.jpg", UriKind.Relative));

using (var ellipseSource = new BitmapImageSource(ellipseImage.AsBitmap()))
using (var ellipse = new EllipseShapeFilter(ellipseSource, white, origin))
{
    ellipseImage = await new WriteableBitmapRenderer(ellipse, ellipseImage).RenderAsync();
}

ImageViewer.Source = ellipseImage;

using (var backgroundSource = new BitmapImageSource(ellipseImage.AsBitmap()))
using (var foregroundSource = new BitmapImageSource(image.AsBitmap()))
using (var filterEffect = new FilterEffect(backgroundSource))
{
    using (BlendFilter blendFilter = new BlendFilter())
    {
        blendFilter.ForegroundSource = foregroundSource;
        blendFilter.BlendFunction = BlendFunction.Darken;

        filterEffect.Filters = new[] { blendFilter };

        var OutputBitmap = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
        var result = await new WriteableBitmapRenderer(filterEffect, OutputBitmap).RenderAsync();

        ImageViewer.Source = result;
    }
}

Github - BlendImageSample

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM