2
從標題可以看到,這個問題已經在過去討論過了。我已經把之前的帖子作爲參考,並嘗試在Zebra標籤打印機上打印位圖圖像。我無法打印我正在尋找的圖像。正如討論過的,請不要忽略。在ZPL標籤打印機上打印位圖圖像
請查看代碼片斷如下所述:
private string TestImage()
{
string filepath = Application.StartupPath + "\\ImageSymbols\\CSA.bmp";
byte[] bitmapFileData = System.IO.File.ReadAllBytes(filepath);
int fileSize = bitmapFileData.Length;
// Retrieve the image.
Bitmap image1 = new Bitmap(filepath, true);
//Siva - Not in use
Rectangle rect1 = new Rectangle(0, 0, image1.Width, image1.Height);
System.Drawing.Imaging.BitmapData bmpData1 =
image1.LockBits(rect1, System.Drawing.Imaging.ImageLockMode.ReadWrite,
image1.PixelFormat);
//Gets the height and width of the bitmap file
int bitmapDataHeight = image1.Height;
int bitmapDataWidth = image1.Width;
//Gets the size of the bitmap file
long bitmapDataFileSize = new FileInfo(filepath).Length;
//Gets the size of the bitmap file in integer
int bitmapDataFileSizeInt = Convert.ToInt32(bitmapDataFileSize);
//Gets the bitmap offset data in bytes.
byte[] test = bitmapFileData.Skip(10).Take(1).ToArray();
//assigns the bitmap offset data to a array value
byte bitmapDataOffset = test[0]; // i am getting offset value = 62
//changes the bitmap offset data to a integer value
int bitmapDataOffsetInt = Convert.ToInt32(bitmapDataOffset);
//gets the bitmap data file size by subtracting the file size with the bitmap offset data size
int bitmapDataSize = bitmapDataFileSizeInt - bitmapDataOffset;
//int width = 80;
//int height = 80;
int bitsPerPixel = 1; // Monochrome image required!
//int bitmapDataLength = 8160;
double widthInBytes = Math.Ceiling(bitmapDataWidth/8.0);
// Copy over the actual bitmap data from the bitmap file.
// This represents the bitmap data without the header information.
byte[] bitmap = new byte[bitmapDataSize];
//bmpData1
Buffer.BlockCopy(bitmapFileData, bitmapDataOffset, bitmap, 0, bitmapDataSize);
// Invert bitmap colors
for (int i = 0; i < bitmapDataSize; i++)
{
bitmap[i] ^= 0xFF;
}
// Create ASCII ZPL string of hexadecimal bitmap data
string ZPLImageDataString = BitConverter.ToString(bitmapFileData);
ZPLImageDataString = ZPLImageDataString.Replace("-", string.Empty);
string str = "";
return str = "^XA^FO100,100^GFA," + //At Postion 100, 100
bitmapDataSize.ToString() + "," + // Total bytes of data to be placed
bitmapDataSize.ToString() + "," + // Total bytes of data to be placed, repeats as per API
widthInBytes + "," + //
ZPLImageDataString + "^XZ";
通過上述示例代碼我不能夠打印在Zibra標籤打印機中的位圖圖像。 我不想使用斑馬網橋將bmp轉換爲GRF圖像類型。
任何人都可以告訴我我犯的錯誤在哪裏? 是我得到偏移值錯誤的方式? (目前它的62,不知道我的圖像其正確與否。誰能建議我找到位圖圖像偏移值的公式)
嗨蒂斯勒,謝謝你的回覆。 –
我試圖使用Zebra SDK,我在導入非託管DLL(無法提取這些DLL,第三方工具限制的方法)時遇到問題。有沒有其他方法可以修改代碼,以便我可以解決在RZ400標籤打印機上打印位圖圖像的問題。我怎樣才能縮放給定的圖像?請幫助我。 –
我可以使用Multiplatform SDK的幫助進行打印,但這不會解決我的問題,因爲我必須準備好ZPL命令。正如你所評論的那樣,我的C#解決方案需要一些擴展,你能幫我解決這個問題嗎? –