3

自分のニーズには大きすぎるgif画像があります(100〜300kbでも)

フォトショップでは、使用している色の数を2(白黒)に減らすだけで、160kbのgifを15kb(彼のサイズの1/10 !!)に変えることができました。

私は自分のアプリケーションで同じことをしたかったのですが、見つけたのは画像をグレースケールに変えて、160kbのgifを100kbに​​変えたことだけでした。

とにかく私のgifを完全な白黒に変える方法はありますか?gifをさらに小さいサイズに縮小できる他の方法があれば幸いです。

4

6 に答える 6

4

これは、それをビトナルG4圧縮TIFFに変換する方法のコードプロジェクトの例です。これは、空白やテキストが多い画像には適していますが、画像にはあまり適していません。画像の場合は、他の答えを確認してディザリングを使用することをお勧めします。

于 2011-05-27T17:51:23.233 に答える
1

SOにはいくつかのコードがあります:Bayer Ordered Ditheringは、私が思う(テストされていない)ことを行うことになっています。試すだけの価値があります。

于 2011-05-27T17:51:05.627 に答える
1

C#で画像を白黒に変換する

/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System.Drawing;
using System.Drawing.Imaging;
#endregion

 namespace Utilities.Media.Image
 {
    /// <summary>
    /// Helper class for setting up and applying a color matrix
     /// </summary>
     public class ColorMatrix
    {
         #region Constructor

        /// <summary>
        /// Constructor
         /// </summary>
         public ColorMatrix()
         {
       }

         #endregion

           #region Properties

         /// <summary>
         /// Matrix containing the values of the ColorMatrix
         /// </summary>
         public float[][] Matrix { get; set; }

         #endregion

         #region Public Functions

         /// <summary>
         /// Applies the color matrix
         /// </summary>
         /// <param name="OriginalImage">Image sent in</param>
         /// <returns>An image with the color matrix applied</returns>
        public Bitmap Apply(Bitmap OriginalImage)
         {
             using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
             {
                 System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(Matrix);
                 using (ImageAttributes Attributes = new ImageAttributes())
                {
                     Attributes.SetColorMatrix(NewColorMatrix);
                     NewGraphics.DrawImage(OriginalImage,
                         new System.Drawing.Rectangle(0, 0, OriginalImage.Width, OriginalImage.Height),
                         0, 0, OriginalImage.Width, OriginalImage.Height,
                         GraphicsUnit.Pixel,
                         Attributes);
                 }
             }
             return NewBitmap;
         }

         #endregion
     }
 }


 /// <summary>
/// Converts an image to black and white
/// </summary>
/// <param name="Image">Image to change</param>
/// <returns>A bitmap object of the black and white image</returns>
public static Bitmap ConvertBlackAndWhite(Bitmap Image)
{
     ColorMatrix TempMatrix = new ColorMatrix();
    TempMatrix.Matrix = new float[][]{
                     new float[] {.3f, .3f, .3f, 0, 0},
                    new float[] {.59f, .59f, .59f, 0, 0},
                     new float[] {.11f, .11f, .11f, 0, 0},
                    new float[] {0, 0, 0, 1, 0},
                    new float[] {0, 0, 0, 0, 1}
                };
     return TempMatrix.Apply(Image);
}

 float[][] FloatColorMatrix ={ 
         new float[] {1, 0, 0, 0, 0}, 
         new float[] {0, 1, 0, 0, 0}, 
        new float[] {0, 0, 1, 0, 0}, 
        new float[] {0, 0, 0, 1, 0}, 
         new float[] {0, 0, 0, 0, 1} 
     };
于 2011-05-27T17:59:18.123 に答える
1

これにはImageMagickを使用できます。によってコマンドラインから実行するかProcess.Start、Windowsインストールの一部であるCOMインターフェイスを使用します。オプション「-モノクロ」はあなたの友達です。

于 2011-05-27T17:59:48.093 に答える
0

フロイド-スタインバーグディザリングを調べてください:http://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering

または、ディザリングが必要ない場合は、平均明度を見つけて、その上のすべてのピクセルを白に、その下のすべてのピクセルを黒に変えます。

于 2011-05-27T17:48:44.090 に答える
-1

ChuckConwayによって投稿されたソリューションの作業バージョン

 /*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

using System.Drawing;
using System.Drawing.Imaging;

namespace WebCamService {
    class ColorMatrix {

        public float[][] Matrix { get; set; }

        public Bitmap Apply(Bitmap OriginalImage) {
            using (Graphics NewGraphics = Graphics.FromImage(OriginalImage)) {
                System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(Matrix);
                using (ImageAttributes Attributes = new ImageAttributes()) {
                    Attributes.SetColorMatrix(NewColorMatrix);
                    NewGraphics.DrawImage(OriginalImage,
                        new System.Drawing.Rectangle(0, 0, OriginalImage.Width, OriginalImage.Height),
                        0, 0, OriginalImage.Width, OriginalImage.Height,
                        GraphicsUnit.Pixel,
                        Attributes);
                }
            }
            return OriginalImage;
        }

        public static Bitmap ConvertBlackAndWhite(Bitmap Image) {
            ColorMatrix TempMatrix = new ColorMatrix();
            TempMatrix.Matrix = new float[][]{
                     new float[] {.3f, .3f, .3f, 0, 0},
                    new float[] {.59f, .59f, .59f, 0, 0},
                     new float[] {.11f, .11f, .11f, 0, 0},
                    new float[] {0, 0, 0, 1, 0},
                    new float[] {0, 0, 0, 0, 1}
                };
            return TempMatrix.Apply(Image);
        }


    }
}
于 2017-08-10T14:38:14.547 に答える