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

  • 相关阅读:
    tcpip详解笔记(1) 概述
    tcpip详解笔记(11) 广播和多播
    tcpip详解笔记(13) tftp
    tcpip详解笔记(15) TCP协议连接过程
    tcpip详解笔记(8) traceroute
    tcpip详解笔记(5) RARP协议
    tcpip详解笔记(6) icmp协议
    tcpip详解笔记(7) ping
    tcpip详解笔记(4) arp协议
    tcpip详解笔记(3) IP网际协议
  • 原文地址:https://www.cnblogs.com/wzwyc/p/9358350.html
Copyright © 2011-2022 走看看