1

一種方法是這樣的:如何自定義的ImageSource喂到圖像中的XAML設置在XAML圖像的ImageSource的

<Image Width="75" Height="75"> 
    <Image.Source> 
     <BitmapImage UriSource={Binding Uri} DecodePixelWidth="75" DecodePixelHeight="75" /> 
    <Image.Source> 
</Image> 

該代碼包含一個很好的優化,因爲一個潛在的大位圖將被解碼75x75像素。

我希望能夠用我的自定義類來代替的BitmapImage這樣的:

<Image Width="75" Height="75"> 
    <Image.Source> 
     <custom:PictureBitmap Picture={Binding Picture} Width="75" Height="75" /> 
    <Image.Source> 
</Image> 

我的應用程序實現了圖片類,它映射到數據庫表。圖片類具有創建BitmapImage實例所需的一切。因此,PictureBitmap本質上是BitmapImage的適配器。

這是我如何開始:

public class PictureBitmap : BitmapSource 
{ 
    // TODO: create Picture Dependency Property 
    // TODO: create a BitmapImage from Picture 
    // TODO: implement abstract methods by delegating calls to BitmapImage 
} 

雖然的BitmapSource是抽象的,在API reference沒有解釋如何實現它。

有誰知道如何將自定義對象提供給Image.Source?

我的應用程序支持Windows Phone Mango(7.5)及更高版本。

謝謝!

回答

0

通過採取附加的屬性方法解決了這個問題。

要使用我的自定義邏輯設置上的圖像的來源屬性,我做了以下內容:

<Image Width="75" Height="75" my-namespace:PictureBitmap.Source={Binding Picture} /> 

該鏈接竟然是極大的幫助:https://stackoverflow.com/a/16103494/1809457

另外,我注意到,DecodePixelWidth和DecodePixelHeight屬性在Mango中不可用。

Mango提供PictureDecoder類,但缺點是它必須在UI線程上使用。

相關問題