我已就此问题进行了一些广泛的搜索,并找到了很少的支持文档。
我正在尝试使用一个简单的条形码拍摄已存在的图像Download here,并在项目的PCL层中处理条形码。
以下是我正在处理的代码:
private void ReadBarcode()
{
try
{
var imageBytes =imagingHelper.GetImage(ImagePath);
var width = imagingHelper.GetWidth(ImagePath);
var height = imagingHelper.GetHeight(ImagePath);
LuminanceSource source = new ZXing.RGBLuminanceSource(imageBytes, (int)width, (int)height);
HybridBinarizer hb = new HybridBinarizer(source);
var a = hb.createBinarizer(source);
BinaryBitmap bBitmap = new BinaryBitmap(a);
BarcodeReader reader = new BarcodeReader();
reader.Options.TryHarder = true;
MultiFormatReader reader1 = new MultiFormatReader();
try
{
var r = reader1.decodeWithState(bBitmap);
var result = reader.Decode(source);
var result2 = reader.DecodeMultiple(source);
if (result != null)
{
return;
}
return;
}
catch (Exception ex)
{
HandleError("ReadBarcode Error: ",ex.Message);
}
}
catch (Exception ex)
{
HandleError("ReadBarcode Error: ", ex.Message);
}
}
用于图像助手(在android级别)
public override uint GetWidth(string photoPath)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.InPreferredConfig = Bitmap.Config.Argb8888;
Bitmap bitmap = BitmapFactory.DecodeFile(photoPath, options);
return bitmap.GetBitmapInfo().Width;
}
public override uint GetHeight(string photoPath)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.InPreferredConfig = Bitmap.Config.Argb8888;
Bitmap bitmap = BitmapFactory.DecodeFile(photoPath, options);
return bitmap.GetBitmapInfo().Height;
}
public override byte[] GetImage(string photoPath)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.InPreferredConfig = Bitmap.Config.Argb8888;
Bitmap bitmap = BitmapFactory.DecodeFile(photoPath, options);
var width = bitmap.GetBitmapInfo().Width;
var height = bitmap.GetBitmapInfo().Height;
int size = bitmap.RowBytes * (int)bitmap.GetBitmapInfo().Height;
ByteBuffer byteBuffer = ByteBuffer.Allocate(size);
bitmap.CopyPixelsToBuffer(byteBuffer);
byte[] byteArray = new byte[byteBuffer.Remaining()];
byteBuffer.Get(byteArray);
return byteArray;
}
我的每一个结果都显示为空,我不确定如何继续。我已经下载了最新的测试包和xamarin表格2.1.0.6529
这方面的任何帮助都会很棒我不确定是否有什么问题或是什么。
我还应该注意,即使在Android级别,它似乎也不会返回结果。