我正在开发一个用于打开/关闭手机摄像头的小部件.
我创建了一个可以像切换按钮(开/关)一样工作的小部件.
行为如下所示:当我启用小部件时,有时候led灯仍然亮着.但它不会打开/关闭相机,但它会改变图标.
我无法弄清楚实际问题是什么.
在Activity(火炬之光应用程序)中同样适用.
任何人都可以解释我如何解决我的问题?
我哪里错了?
你可以查看我到目前为止所做的代码
onUpdate 方法
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
//super.onUpdate(context, appWidgetManager, appWidgetIds);
remoteViews = new RemoteViews( context.getPackageName(), R.layout.widgetlayout);
watchWidget = new ComponentName( context, FlashLightWidget.class );
Intent intentClick = new Intent(context,FlashLightWidget.class);
intentClick.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, ""+appWidgetIds[0]);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetIds[0],intentClick, 0);
remoteViews.setOnClickPendingIntent(R.id.myToggleWidget, pendingIntent);
appWidgetManager.updateAppWidget( watchWidget, remoteViews );
ctx=context;
}
Run Code Online (Sandbox Code Playgroud)
onReceive 方法如下:
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
remoteViews = new RemoteViews( context.getPackageName(), R.layout.widgetlayout);
if (intent.getAction()==null) …Run Code Online (Sandbox Code Playgroud) android widget android-widget android-camera android-appwidget
我看了一下,但似乎没有一个坚实的答案/解决方案,非常恼人的问题.
我以纵向拍摄照片,当我点击保存/放弃时,按钮的方向也正确.问题是,当我稍后检索图像时,它是横向的(图片已逆时针旋转90度)
我不想强迫用户以特定方向使用相机.
有没有办法可以检测照片是以纵向模式拍摄,然后解码位图并以正确的方式翻转它?
根据该文件,setRotation(90)应旋转拍摄的JPEG图片(takePicture在横向模式.
这在HTC手机上运行良好,但在三星Google Nexus S和三星Galaxy S3上无效.这是一个错误吗?
我知道我可以使用矩阵变换旋转,但希望操作系统可以更有效地执行此操作,并且不希望在某些其他设备上存在过度旋转的风险.
编辑
设置camera.setDisplayOrientation(90);使预览处于纵向模式,但它对拍摄的照片没有任何影响.
此外,另外setRotation,我也试图设置图片大小-在我翻转h用w:parameters.setPictureSize(1200, 1600);.这也没有任何影响.
解
显然,三星手机设置了EXIF方向标签,而不是旋转单个像素.如ariefbayu建议的那样,使用Bitmap BitmapFactory不支持此标记.他的代码示例是解决方案,此解决方案也与使用兼容inSampleSize.
我正在尝试使用OpenCV 2.4.3.2创建一个相机应用程序并进行一些opencv处理.我希望它能够有多个UI方向,而不仅仅是Landscape.
问题是,当我将方向更改为纵向时,图像会侧向出现.
我知道我可以在进行图像处理之前旋转输入图像(因此只将方向保留为横向),这很好并且有效,但是没有解决我的其他UI将处于错误方向的问题.
我也尝试使用这段代码来旋转相机90deg,但它似乎没有用.
mCamera.setDisplayOrientation(90);
Run Code Online (Sandbox Code Playgroud)
它要么没有效果,要么有时只会导致预览变黑
有人用OpenCV成功完成了这项工作吗?我的类扩展自JavaCameraView.

我做了一些改进,就是我在OpenCV中旋转了图像,因为它在CameraBridgeViewBase.java类中显示.
在交付和绘制框架方法中:
if (canvas != null) {
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
//canvas.drawBitmap(mCacheBitmap, (canvas.getWidth() - mCacheBitmap.getWidth()) / 2, (canvas.getHeight() - mCacheBitmap.getHeight()) / 2, null);
//Change to support portrait view
Matrix matrix = new Matrix();
matrix.preTranslate((canvas.getWidth() - mCacheBitmap.getWidth()) / 2,(canvas.getHeight() - mCacheBitmap.getHeight()) / 2);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
matrix.postRotate(90f,(canvas.getWidth()) / 2,(canvas.getHeight()) / 2);
canvas.drawBitmap(mCacheBitmap, matrix, new Paint());
Run Code Online (Sandbox Code Playgroud)
...基本上,这只是像输入图像一样

这样更好,但我显然希望这是全屏.
我需要捕获图像 从 所需部分中的屏幕.
从相机捕获图像.
那时其他屏幕内容就是这样.

这怎么可能?
android image-capture surfaceview android-camera camera-view
我在捕获图像并将其存储在本机相机应用程序时遇到问题.以下是我的一些代码示例.
_path = Environment.getExternalStorageDirectory() + "make_machine_example.jpg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
startActivityForResult( intent, 0 );
Run Code Online (Sandbox Code Playgroud)
拍完照片后我又回到原来的活动中,当我通过Android DDMS文件浏览器导航到我的SD卡时,图片不存在.任何人都知道为什么没有得救?
camera android android-intent android-camera android-camera-intent
我已经浏览了一些链接,以获得从默认图库中选择的图像的正确图像方向,以便在exif标记始终返回0的所有设备中标准化.
对于使用肖像相机应用程序android拍摄的图像,EXIF方向标记值始终为0
http://mobisocial.stanford.edu/news/2011/08/rotating-images-in-android/
如何获得适用于所有设备的精确解决方案?
我正在使用Android vision API中的FaceTracker示例.但是,我在录制视频时遇到了困难,同时在它们上面绘制了叠加层.
一种方法是将位图存储为图像并使用FFmpeg或Xuggler将它们合并为视频,但我想知道如果我们可以在预计投影时在运行时录制视频,是否有更好的解决方案.
更新1: 我使用媒体记录器更新了以下类,但录制仍然无法正常工作.当我调用triggerRecording()函数时抛出以下错误:
MediaRecorder:以无效状态调用:4
我在清单文件中有外部存储权限.
更新2:
我在代码中修复了上述问题,并在onSurfaceCreated回调中移动了setupMediaRecorder().但是,当我停止录制时,它会抛出运行时异常.根据文档,如果没有视频/音频数据,将抛出运行时异常.
那么,我在这里错过了什么?
public class CameraSourcePreview extends ViewGroup {
private static final String TAG = "CameraSourcePreview";
private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
ORIENTATIONS.append(Surface.ROTATION_90, 0);
ORIENTATIONS.append(Surface.ROTATION_180, 270);
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
private MediaRecorder mMediaRecorder;
/**
* Whether the app is recording video now
*/
private boolean mIsRecordingVideo;
private Context mContext;
private SurfaceView mSurfaceView;
private boolean mStartRequested;
private boolean mSurfaceAvailable;
private CameraSource mCameraSource; …Run Code Online (Sandbox Code Playgroud) android android-camera android-mediarecorder google-vision android-vision
我正在使用本机应用程序打开相机的意图:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri photoUri = Uri.fromFile(getOutputPhotoFile());
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, CAMERA_PHOTO_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)
每次打开的相机(前/后相机)都像上次打开本机相机应用程序一样.这意味着如果我最后一次关闭本机相机应用程序时后置摄像头处于活动状态,那么当我启动相机意图时,后置摄像头将处于活动状态.
我想直接启动前置摄像头.有谁知道怎么做?
我正在使用SurfaceView捕获图像并在public void onPreviewFrame4(byte []数据,相机相机)中获取Yuv Raw预览数据
我必须在onPreviewFrame上执行一些图像预处理,所以我需要将Yuv预览数据转换为RGB数据,而不是图像预处理并返回到Yuv数据.
我使用了两个函数来编码和解码Yuv数据到RGB,如下所示:
public void onPreviewFrame(byte[] data, Camera camera) {
Point cameraResolution = configManager.getCameraResolution();
if (data != null) {
Log.i("DEBUG", "data Not Null");
// Preprocessing
Log.i("DEBUG", "Try For Image Processing");
Camera.Parameters mParameters = camera.getParameters();
Size mSize = mParameters.getPreviewSize();
int mWidth = mSize.width;
int mHeight = mSize.height;
int[] mIntArray = new int[mWidth * mHeight];
// Decode Yuv data to integer array
decodeYUV420SP(mIntArray, data, mWidth, mHeight);
// Converting int mIntArray to Bitmap and
// than image …Run Code Online (Sandbox Code Playgroud) android ×10
android-camera ×10
camera ×1
camera-view ×1
image ×1
ocr ×1
opencv ×1
surfaceview ×1
widget ×1
yuv ×1