二维码在哪里 采样二维码在哪里( 四 )

  
m_Width, m_Height);  
setLayoutParams(layParams);  
}  
@Override  
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,  
int arg3) {  
}  
@Override  
public void surfaceCreated(SurfaceHolder arg0) {  
if (m_surfaceThread == null || m_surfaceThread != null  
&& !m_surfaceThread.isAlive()) {  
m_bexit = false;  
m_surfaceThread = new Thread(this);  
m_surfaceThread.start();  
}  
}  
@Override  
public void surfaceDestroyed(SurfaceHolder arg0) {  
Log.i(TAG, "ColorView onDestory!!");  
m_bexit = true;  
m_surfaceThread = null;  
}  
@Override  
public void run() {  
while (!m_bexit) {  
try {  
m_xc.waitforupdate(); // 更新数据  
m_canvas = m_holder.lockCanvas();  
if (m_canvas != null) {  
Paint paint = new Paint();  
paint.setXfermode(new PorterDuffXfermode(  
PorterDuff.Mode.CLEAR));  
m_canvas.drawPaint(paint);  
if (!GlobalDef.USE_UVC) {  
ImageMap imageMap = m_rgbdata.GetImageMap();  
ByteBuffer byteBufferTemp = imageMap  
.createByteBuffer();  
m_pixels = byteBufferTemp.array();  
NativeMethod.GetRGBData(m_pixels, m_rgbIntData,  
m_Width, m_Height, m_versionInt);  
} else {  
if (processor.getRealTimeData() == null  
|| processor.getRealTimeData().length <= 0) {  
continue;  
}  
// Log.d(TAG,"Get Buffer from liveCamera!");  
NativeMethod.NV21ToMirrorRGBA(  
processor.getRealTimeData(), m_rgbIntData,  
GlobalDef.RES_UVC_WIDTH,  
GlobalDef.RES_UVC_HEIGHT);  
// Log.d(TAG,"Get Buffer from liveCamera!!!!!");  
}  
m_colorBitmap.setPixels(m_rgbIntData, 0, m_Width, 0, 0,  
m_Width, m_Height);  
if (m_colorBitmap != null) {  
m_canvas.drawBitmap(m_colorBitmap, 0, 0, null);  
/*  
* 获取帧图片中的二维码并且显示出来**********************************  
* ****************************  
*/  
Result result = scanningImage(m_colorBitmap);  
// String result = decode(photo_path);  
if (result == null) {  
Log.i("123", "二维码图片格式不正确");  
} else {  
Log.i("123result", result.toString());  
// 数据返回  
final String recode = recode(result.toString());  
if(!isDialogShow){  
Message msg = Message.obtain();  
msg.obj = recode;  
updateHandler.sendMessage(msg);  
isDialogShow = true;  
}  
}  
/**********************************************************************************************/  
}  
m_holder.unlockCanvasAndPost(m_canvas);  
}  
} catch (Exception e1) {  
// TODO Auto-generated catch block  
e1.printStackTrace();  
}  
}  
}  
}  
//  
/**  
* 解析部分图片  
*  
* @author jcq  
* @param Bitmap 扫码获取到的bitmap  
* @return 二维码解析出来的字符串结果  
*/  
protected Result scanningImage(Bitmap scanBitmap) {  
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();  
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码  
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);  
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));  
QRCodeReader reader = new QRCodeReader();  
try {  
return reader.decode(bitmap1, hints);  
} catch (NotFoundException e) {  
e.printStackTrace();  
} catch (ChecksumException e) {  
e.printStackTrace();  
} catch (FormatException e) {  
e.printStackTrace();  
}  
return null;  
}  
/**  
* 中文乱码,能解决大部分的中文乱码  
*  
* @author jcq  
* @return 解码后的字符串  
*/  
private String recode(String str) {  
String formart = "";  
try {  
boolean ISO = Charset.forName("ISO-8859-1").newEncoder()


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。