3

ユーザー入力からビットマップ画像を作成するライブラリを作成しました。このビットマップは、ゼブラ プリンタを使用して印刷されます。私が直面している問題は、ゼブラ プリンターで印刷された画像ではすべてが非常にかすかでぼやけていることですが、ビットマップをレーザー プリンターで印刷すると完全に正常に見えます。以前に誰かがこれに遭遇したことがありますか?もしそうなら、どうやって修正しましたか? プリンターの設定について考えられることはほぼすべて試しました。

ビットマップ画像を作成する方法のコードで更新されました。

public static Bitmap GenerateLabel<T>(T obj, XmlDocument template)
    {
        try
        {
            int width = Convert.ToInt32(template.SelectSingleNode("/LABELS/@width").Value);
            int height = Convert.ToInt32(template.SelectSingleNode("/LABELS/@height").Value);

            if (obj == null || height <= 0 || width <= 0)
                throw new ArgumentException("Nothing to print");

            Bitmap bLabel = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bLabel);

            XmlNodeList fieldList = template.SelectNodes("/LABELS/LABEL");

            foreach (XmlNode fieldDetails in fieldList)
            {
                //non important code...

                    g.DrawImage(bBarCode, field.Left, field.Top);


                using (TextBox txtbox = new TextBox())
                {
                    // more non important code...

                    Rectangle r = new Rectangle(field.Left, field.Top, field.Width, field.Height);
                    txtbox.DrawToBitmap(bLabel, r);
                }
            }

            return bLabel;
        }
        catch (Exception ex)
        {
            throw new Exception("Unable to create bitmap: " + ex.Message);
        }
    }
4

6 に答える 6

5

Zebraプリントドライバーが出力をディザリングしています。Zebra印刷に最適な画像を作成するには、203 DPIおよび2色の白黒(1ビット)で画像を作成する必要があります。

于 2010-04-23T20:18:02.893 に答える
2

I ended up using a third party library called Thermal SDK which allowed me to draw/save my bitmap and then send it to the zebra printer in the 'special' format it needed. It works for single labels but if you wanted to do many at a time it would be pretty inefficient since you have to save each label to a file before you can print it.

于 2010-04-23T20:06:21.547 に答える
2

これは、すべての zebra プリンタに共通の「機能」です。ドライバは、プリンタ自体に送信する前に非可逆技術を使用して画像を圧縮します。私が知る限り、回避策はありません。

于 2010-04-22T09:59:47.680 に答える
2

プリンタには 1 bpp のモノクロ イメージが必要です。また、カラーまたはグレースケールの画像をモノクロに変換するための完全なアルゴリズムはありません。このようなアルゴリズムは、画像によっては良い結果が得られる場合とそうでない場合があります。そのため、Mike Ransom 氏が前述したように、最初からモノクロになるように画像を準備するのが最善の方法です。ただし、プログラムで行う必要がある場合は、最初のカラー画像で黒と白の色のみを使用する必要があり (変換で適切な結果が得られるようにするため)、次のようなアルゴリズムを使用できます (ソース リンクはこちら)。

public static Bitmap BitmapTo1Bpp(Bitmap img)
   {
       int w = img.Width;
       int h = img.Height;

       Bitmap bmp = new Bitmap(w, h, PixelFormat.Format1bppIndexed);
       BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);

       for (int y = 0; y < h; y++)
       {
           byte[] scan = new byte[(w + 7) / 8];

           for (int x = 0; x < w; x++)
           {
               Color c = img.GetPixel(x, y);
               if (c.GetBrightness() >= 0.5) scan[x / 8] |= (byte)(0x80 >> (x % 8));
           }

           Marshal.Copy(scan, 0, (IntPtr)((int)data.Scan0 + data.Stride * y), scan.Length);
       }

       bmp.UnlockBits(data);

       return bmp;
   }
于 2012-02-01T11:26:59.677 に答える
1

答えは簡単です。Zebraプリンタは白黒のみを印刷するため、画像をプリンタに送信する前に、画像を白黒に変換してください。

私はC#コーダーではありませんが、VBコードは似ているので、彼の助けを期待しています。

    ''' <summary>
''' Converts an image to Black and White
''' </summary>
''' <param name="image">Image to convert</param>
''' <param name="Mode">Convertion mode</param>
''' <param name="tolerance">Tolerancia del colores</param>
''' <returns>Converts an image to Black an white</returns>
''' <remarks></remarks>
Public Function PureBW(ByVal image As System.Drawing.Bitmap, Optional ByVal Mode As BWMode = BWMode.By_Lightness, Optional ByVal tolerance As Single = 0) As System.Drawing.Bitmap
    Dim x As Integer
    Dim y As Integer
    If tolerance > 1 Or tolerance < -1 Then
        Throw New ArgumentOutOfRangeException
        Exit Function
    End If
    For x = 0 To image.Width - 1 Step 1
        For y = 0 To image.Height - 1 Step 1
            Dim clr As Color = image.GetPixel(x, y)
            If Mode = BWMode.By_RGB_Value Then
                If (CInt(clr.R) + CInt(clr.G) + CInt(clr.B)) > 383 - (tolerance * 383) Then
                    image.SetPixel(x, y, Color.White)
                Else
                    image.SetPixel(x, y, Color.Black)
                End If
            Else
                If clr.GetBrightness > 0.5 - (tolerance / 2) Then
                    image.SetPixel(x, y, Color.White)
                Else
                    image.SetPixel(x, y, Color.Black)
                End If
            End If
        Next
    Next
    Return image
End Function
于 2010-07-28T18:15:15.530 に答える
1

ドライバの設定、プリンタの dpi を確認すると、損失の多い手法だけでなく、影響を引き起こす可能性のある多くの設定があります。

多くのビットマップ イメージをゼブラとインターメック サーマルに送信しました。動作するはずです。

于 2010-04-23T20:00:36.157 に答える