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

  • 相关阅读:
    php解析.csv文件
    sublime text3 输入中文的解决方法
    git 的使用
    yii2.0 框架邮件的发送
    yii2.0的分页和排序
    php上传图片文件常用的几个方法
    在yii框架中如何连接数据库mongodb
    yii框架中验证器声明一组内置验证器可以使用短名称引用
    yii中的cookie的发送和读取
    ExpressionToSQL
  • 原文地址:https://www.cnblogs.com/wzwyc/p/9358350.html
Copyright © 2011-2022 走看看