【问题标题】:XAML: Image should show specific bitmap frameXAML:图像应显示特定的位图框
【发布时间】:2014-09-24 09:04:44
【问题描述】:

以下是一篇简短的文章,应该可以帮助您了解我的痛苦;( 我试图在图像控件中显示特定的位图框架(Tif 页面)。但我找不到任何合适的图像控件成员。

<Image>
    <Image.Source>
        <BitmapImage 
            DecodePixelWidth="500"
            UriSource="C:\...\MultiPage.tif" 
            CacheOption="OnLoad" 
            CreateOptions="PreservePixelFormat"
            RenderOptions.BitmapScalingMode="HighQuality"
            RenderOptions.EdgeMode="Aliased"
            <!--The following line does not work of course but it should show what I mean:-->
            BitmapFrameIndex="3" 
        />
    </Image.Source>
</Image>

【问题讨论】:

    标签: wpf image xaml bitmap


    【解决方案1】:

    您可以使用TiffBitmapDecoder Class 在代码中执行此操作,但我不太确定它是否可以完全在 XAML 中完成。 TiffBitmapDecoder.Frames property 提供对图像中各个帧的访问:

    TiffBitmapDecoder tiffBitmapDecoder = new TiffBitmapDecoder(new Uri(filename), 
        BitmapCreateOptions.None, BitmapCacheOption.None);
    

    然后你可以像这样访问单个框架:

    BitmapFrame bitmapFrame = tiffBitmapDecoder.Frames[yourRequiredIndex];
    

    或者从它创建一个BitmapSource 实例:

    BitmapSource bitmapSource = tiffBitmapDecoder.Frames[yourRequiredIndex];
    

    由于BitmapSource Class 扩展了ImageSource 类,您应该可以直接将其设置为Image.Source 值:

    YourImage.Source = bitmapSource;
    

    【讨论】:

    • @NoelWidmer 您也许可以将其包装在派生的 BitmapSource 中以使其在 XAML 中可用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2022-11-16
    • 1970-01-01
    相关资源
    最近更新 更多