Touchable screen while using camera - android-camera

I'm really stuck on my work. I read a lot of questions&answers on stackoverflow but still I can't find the exact answer that would suit me. Please help me or even just point me in the right direction...
I'm trying to write an application that would let me choose an object on the screen while using the camera.
I'll try to explain it in a more simple way:
I turn on the application, the camera live screen appears as if I was recording something. I use my finger and select 3 specific points on the screen (these would be small color paper squares I've prepared earlier). My choice is saved to the phone.
(I'll stop here because I think further explanation of what happens next is not important here).
I don't know how to create a program/code that would let me select those points on the screen. All I have now is a simple code that only turns on the camera and lets you record videos.
Please help.

You're code to start the video feed, I would assume, gets a Camera object, starts it and connects it to a SurfaceView maybe a SurfaceTexture. The frames from the Camera are directly displayed to the SurfaceView if you have set:
myHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
myCamera.setPreviewDisplay(myHolder);
This is a fast and easy way to display the camera frames, but it means you cannot control how the frames are displayed. For instance, if you wanted to process the frames and then display them yourself, you would need to subscribe to the onPreviewCallback() which gives you a copy of each frame. If you then omitted the above two surfaceview lines, the frames would not be automatically displayed and you could draw them yourself, however this would be alot slower. https://stackoverflow.com/a/4367250/514531
You can draw on top of a surfaceview using a Canvas. A canvas has many methods for drawig shapes/rectangles/lines/circles/words etc. You use Paint objects to specfify color/width etc.
Im sorry if this is wrong now but I have been using an older Android, but, if you do display via the surfaceview you cannot lock a canvas to the surfaceview. https://stackoverflow.com/a/12565208/514531 To get around this I found some code a while ago which creates an OverlayView class. In Android you can place views on top of each other in the Z direction. Using an empty transparent surfaceview that doesnt use myHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); myCamera.setPreviewDisplay(myHolder); you can lock a canavs to it and start drawing.
The OverlayView class is simply a class extending SurfaceView and is used as a custom display. To do this you need to declare it in your layout file for your first/camera activity, like this:
<Your.package.OverlayView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/overView"
/>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surfaceView"/>
In this layout file R.id.surfaceView is your first surfaceview you use with the camera and set up like you probably already have. The R.id.overView is the custom surfaceview for drawing.
You can create it like any other view component:
OverLayView overView = (OverlayView)findViewById(R.id.overView);
This acts like a normal class as well so you can send some parameters to it as normal and call methods on it. For instance I have a method:
overView.setCamera(myCamera, cameraHeight, cameraWidth, getResources(), isFrontCamera);
Now you have a camera displaying to a surfaceview and a separate surfaceview you can draw to. So you now need a TouchEvent handler.
In the OverlayView class override the method onTouchEvent(MotionEvent e). The MotionEvent tells you what event occured, touch on/off. First check that it is a touch down(press on the screen) and then you can get the X and Y coordinates from the MotionEvent e.getX;
This could be combined with the canavs to draw where a touch as occurred.
On thing to note: The dimensions of the camera preview will probably be different to that of the surfaceview. You know the camera dimensions from the camera object and the surfaceview sizes are from the surfaceView onchange method. So you need to calculate a ratio to convert the two, something like: (viewWidth/touch)*camerawidth.
Once you have the coordinates you could use crop the camera frame where you want.

Related

How to find the dimensions of screen in Flutter Flame Game without Camera?

I have a Flame Game app that I want to adjust to make it available on all kinds of screens, but my app doesn't use a world or camera. All of the solutions that I've found for finding screen size in Flutter seem to use these items. I don't need a world or camera, but I don't know if there's a way that I can find the screen size without it?
I've tried researching this, but can only find solutions using world or camera.
tYou can get the size of the canvas by just checking the size variable in your FlameGame class. (gameRef.size if you want to use it from a Component that has the HasGameRef mixin)
There is a built-in camera in the FlameGame class if you want to apply a FixedResolutionViewport, which sounds like what you want to do? This is the only line you have to add to do that, preferably in your game class's onLoad method:
camera.viewport = FixedResolutionViewport(Vector2(800, 600));

switching from one camera to other in unity ,view entering from right

I have two cameras in the same position.I want to switch from one camera to other (with a transition effect) such that second view replaces the first camera view entering from the left side moving inwards and filling the screen.. Camera fading in and fading out effects are available in unity wiki..Can anyone suggest me a technique to achieve this effect..
You can try to animate Camera.rect. Otherwise you will have to render both in a RenderTexture and combine rendered images in a small shader with a translate parameter changing from 0 to 1.
While i'm not really really sure of the application for the switching of the camera if you were to instantiate it dynamically you would be able to use lerp and other function calls to manipulate behavior and not need to use multiple cameras.
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html
As a side note i'm sure you could reverse engineer some camera effects similar to this one in order to achieve the background(a little confused about what you want to do with that)
http://docs.unity3d.com/Documentation/Components/script-CameraMotionBlur.html

How can I create a tile, overlay for a scene in Cocos2d?

I'm new to Cocos2d, but I can't seem to find the answer to this. I want to add an image that is mostly transparent as an overlay to my application. The image is overlayed on the app, and does not respond to screen taps. All gestures should "pass through" to the application.
The overlay image should actually be tiled. It's a small image that should repeat both horizontally and vertically.
How can I do this? In fact, this is an overlay that I would like to display for the duration of the entire application-- not just one specific scene. Is there a simple way to do this?
The point of my overlay is that I'd like to create a pseudo-scan line affect for a game which has an "8-bit" tone. The scan lines will be generated by applying the overlay to the game. The overlay is non-interactive and should always exist. So, this isn't a "tile based game", but I do need a tiling affect for this functionality.
You should be able to create a layer in each scene, set the zOrder to something large so that it overlays everything else, and set its isTouchEnabled attribute to NO. You can then add whatever you want to the layer, which could be your patterned image. To change the alpha, just set the opacity attribute of your image. The only issue that I can foresee is that the overlay might disable touch events for layers below it.

How to display photos like iphone homescreen?

I'm trying to make an app that's displaying my photos from camera roll like app icons in iphone (matrix view) . The pictures will have the "wobble" effect and the pictures need to be rearrangeable(the posibility to swap pictures).
I found out how to implement the wobble efect.
What`s the best way to implement the displaying and swapping functionality?
I suggest you to show your photos using CALayer.
Add those layer in Matrix like pattern in your UIView using frame property of layer.
To move or rearrange photos find particular CALayer in touchesBegin method of View using touch points and Move it with movement in touched(in touchesMoved). Settle it in a proper location in touchesEnded method.
I have assumed that you have basic knowledge of usage of classes that I mentioned in above description.
Post here if you need more help.

Recreating streetview effect in my own iPhone App

My app allows you too "look" around a room in every similar manner to how you can "look" around a street when you are in streetview in the Maps application. Does anyone know of a simple way to recreate this effect?
I do have an image (like the streetview image) that I would like users to look around in.
Some ideas I have:
1) Put the image in a scroll view and let users pan and zoom. This doesn't seem like it would have the same effect as when you pan around the streetview, objects near the edges stretch to give you a "lens" type effect.
2) Apply a transform to the image before drawing it in a scroll view, and reapply the transform during scrolling. This transform would create the lens effect on the currently viewed part of the image.
3) Use open GL to create a hollow sphere and apply the image as a texture on the inside of the sphere.
doesn't seem like it would work
seems like my best option but I don't know what transform to use in quartz to create this effect. I like this though because it uses a scroll view and I don't have to recreate the panning, flicking and pinching code.
seems like overkill and too much work
Any ideas?