原創(chuàng)|使用教程|編輯:何躍|2021-11-29 13:12:02.600|閱讀 245 次
概述:
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Android版本的SDK不能直接從圖像文件中讀取,但它可以使用類似于以下的代碼從位圖中讀取。
	
Barcode barcode = new Barcode();
// Load your image file into a bitmap
int width = bitmap.getWidth();
int height = bitmap.getHeight();
byte[] rawBytes = new byte[width * height * 4];
int index = 0;
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        int colour = bitmap.getPixel(x, y);
        int red = (colour >> 16) & 0xff;
        int green = (colour >> 8) & 0xff;
        int blue = colour & 0xff;
        int alpha = 0;
        int rawIndex = index * 4
        rawBytes[rawIndex++] = (byte) red ;
        rawBytes[rawIndex++] = (byte) green;
        rawBytes[rawIndex++] = (byte) blue;
        rawBytes[rawIndex++] = (byte) alpha;
        index++;
    }
}
int n = barcode.ScanBarCodeFromRGBABitmap(bitmap.getWidth(), bitmap.getHeight(), rawBytes);
if (n > 0)
    strBarcode = barcode.GetBarString(1);
	
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn