String abc ="0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff"
const unsigned char displaydata={ ' " abc "'};
display.drawBitmap(displaydata, startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE)。
這不是顯示,而是
const unsigned char displaydata={ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
display.drawBitmap(displaydata,startX,startY,bmpWidth,bmpHeight,GxEPD_WHITE)。
這就是作業和顯示
我需要用代碼將一個字串轉換為常量無符號字符。這可能嗎?
來自服務器的資料以攪拌的方式回傳給我,我正試圖將其反映在螢屏上。
所以我試圖轉換
uj5u.com熱心網友回復:'" abc "'是一個非法字符字面。你不能像這樣建立一個陣列。在你的第二個例子中,什么看起來像一個陣列
const unsigned char displaydata={ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}。實際上只有一個
const unsigned char。它應該是:const unsigned char displaydata[]={ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
你可能可以這樣定義你的String:
String abc = "xffxffxffxffxff"。
注意,上面的編碼與你的第二個例子相匹配:
const unsigned char displaydata[] = { 0xff, 0xff, ..., 0xff } - 不是你最初在String中的內容。
String有一個名為c_str()的成員函式,回傳"一個指向呼叫String的C風格版本的指標":
display.drawBitmap(abc.c_str(), startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE) 。
//^^^^^^^^。
如果編譯器抱怨說c_str()為display.drawBitmap()回傳錯誤的型別,你可以鑄造:
display. drawBitmap(reinterpret_cast<const unsigned char*> (abc. c_str()。
startX, startY, bmpWidth, bmpHeight, GxEPD_WHITE)。)
uj5u.com熱心網友回復:
String abc ="0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff"
默認的C(或C )庫中沒有String。對于常規的使用,可以考慮-
std::string abc = "0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff"
這將不起作用,因為你需要的是位元組值0xff,而不是字串 "0xff"
。你還需要考慮char、signed char和unsigned char之間的區別。例如,0xFF - 當它被視為有符號的char時,它是負數;但它是255的無符號char。對于char,其表示方法是由編譯器決定的。
如果你要處理二進制資料,最好使用uint8_t - 這與無符號char相同。因此,對于影像處理,使用uint8_t、uint16_t和uint32_t - 這將確保更好的移植性。每個位元組、短位元組和int分別保證為1位元組、2位元組和4位元組,你將避免因符號位而產生的錯誤。
因此,你可以使用
const uint8_t displaydata[]={ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/333971.html
標籤:
