参照リンク:
更新しました
現在、LockBits を使用して画像変換を変更しましたが、失敗しました。誰でも私に何か提案をすることができますか?
/// <summary>
/// Orginal command Format in Decimal:
/// 29[GS], 40[(], 76[L], pL, PH, 48(m), 67[fn], 48[a], kc1, kc2, b, xL, xH, yL, yH, c, [d1 -- dk]
/// pL = Lower bit of sum of parameters (m to dk) = 11(m to c) + last bit of image
/// pH = Higher bit of sum of parameters (m to dk) = 11(m to c) + last bit of image
/// kc = Key Code of NVRam, kc1 = first bit of key code, kc2 = second bit of key code. P.S.: The key code will be hardcode H1.
/// b = number of colors = 1
/// xL & xH = Lower bit of image width, e.g. Width = 128 = 0x0080 then xL = 0x80, xH = 0x00
/// </summary>
/// <param name="pLogo"></param>
public void LoadImageToPrinter(Bitmap pLogo)
{
BitmapData oBmpData = pLogo.LockBits(new Rectangle(0, 0, pLogo.Width, pLogo.Height), ImageLockMode.ReadOnly, pLogo.PixelFormat);
//The list contains all the commands in Decimal format
List<int> oCommandList = new List<int>();
//k = (int((xL + xH × 256) + 7)/8) × (yL + yH × 256)
string HexValueOfX = pLogo.Width.ToString("X4");
string HexValueOfY = pLogo.Height.ToString("X4");
//k
int oExpectedImageByteCount = Math.Abs(oBmpData.Stride) * pLogo.Height;
//Total bit used for parameters
int oTotalParameterBitCount = 11 + oExpectedImageByteCount;
//The hex value for the oTotalParameterBitCount
string oTotalParameterBitCountInHex = oTotalParameterBitCount.ToString("X4").PadLeft(4, '0');
//GS, (, L
oCommandList.AddRange(new int[] { 29, 40, 76 });
//pL
oCommandList.Add(GetLowerHexValue(oTotalParameterBitCountInHex));
//pH
oCommandList.Add(GetHigherHexValue(oTotalParameterBitCountInHex));
//m, fn, a, kc1, kc2, b
oCommandList.AddRange(new int[] { 48, 67, 48, (int)'H', (int)'1', 1 });
//xL, xH
oCommandList.AddRange(new int[] { GetLowerHexValue(HexValueOfX), GetHigherHexValue(HexValueOfX) });
//yL, yH, c
oCommandList.AddRange(new int[] { GetLowerHexValue(HexValueOfY), GetHigherHexValue(HexValueOfY), 49 });
//Append the image bit to the List
byte[] oImageByte = new byte[oExpectedImageByteCount];
IntPtr oPtr = oBmpData.Scan0;
Marshal.Copy(oPtr, oImageByte, 0, oExpectedImageByteCount);
pLogo.UnlockBits(oBmpData);
//Clear NVRam
mThermalPrinterLibrary.Write(new int[] { 29, 40, 76, 5, 0, 48, 65, 67, 76, 82 }.IntArrayToCharString());
//Store graphics data
mThermalPrinterLibrary.Write(oCommandList.ToArray().IntArrayToCharString());
mThermalPrinterLibrary.Write(oImageByte);
//Print the graphics data
mThermalPrinterLibrary.Write(new int[] { 29, 40, 76, 6, 0, 48, 69, (int)'H', (int)'1', 1, 1 }.IntArrayToCharString());
}