标签:
修改竖屏扫描的贴子,2.0之前的都很适用。可是到了2.1,有些贴子的做法可以将扫描框改为竖屏,但是取景框里扫描到的东西是变形的(扁的),本人仔细研究一番,终于解决了这个问题,下面贴出解决办法:
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
camera.setDisplayOrientation(90);
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if (width < height) {
int temp = width;
width = height;
height = temp;
}
screenResolution = new Point(height, width);
cameraResolution = findBestPreviewSizeValue(parameters, new Point(width, height));
第5步应该这样子:
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
previewFormat = parameters.getPreviewFormat();
previewFormatString = parameters.get("preview-format");
WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
screenResolution = new Point(width,height);
if(width < height)
{
cameraResolution = getCameraResolution(parameters, new Point(height,width));
}else{
cameraResolution = getCameraResolution(parameters, screenResolution);
}
}
标签:
原文地址:http://www.cnblogs.com/zmc/p/4704420.html