zoukankan      html  css  js  c++  java
  • 编解码TIFF图像

    解码:

    // Open a Stream and decode a TIFF image
    Stream imageStreamSource = new FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
    TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
    BitmapSource bitmapSource = decoder.Frames[0];
    
    // Draw the Image
    Image myImage = new Image();
    myImage.Source = bitmapSource;
    myImage.Stretch = Stretch.None;
    myImage.Margin = new Thickness(20);

    编码:

    int width = 128;
    int height = width;
    int stride = width / 8;
    byte[] pixels = new byte[height * stride];
    
    // Define the image palette
    BitmapPalette myPalette = BitmapPalettes.WebPalette;
    
    // Creates a new empty image with the pre-defined palette
    
    BitmapSource image = BitmapSource.Create(
        width,
        height,
        96,
        96,
        PixelFormats.Indexed1,
        myPalette,
        pixels,
        stride);
    
    FileStream stream = new FileStream("new.tif", FileMode.Create);
    TiffBitmapEncoder encoder = new TiffBitmapEncoder();
    TextBlock myTextBlock = new TextBlock();
    myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
    encoder.Compression = TiffCompressOption.Zip;
    encoder.Frames.Add(BitmapFrame.Create(image));
    encoder.Save(stream);

    引用:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/graphics-multimedia/how-to-encode-and-decode-a-tiff-image

  • 相关阅读:
    ASP.Net 反射显示
    ASP.Net 反射简单工厂模式
    ASP.Net MVC生成验证码
    ASP.Net EF架构
    ASP.Net 邮箱发送
    ASP.Net 反射简单
    ASP.Net 显示
    新年快乐
    测试开发比
    Linkbot介绍
  • 原文地址:https://www.cnblogs.com/wzwyc/p/9358350.html
Copyright © 2011-2022 走看看