I am working on an app that will show reverse view from camera. For example, if current view from camera is like:
,
the app should reverse view like:
so user will see constantly reverse view from camera through this app.
I am not very sure how to achieve this. Any help or idea would be highly appreciated. Thanks!
I understand from your answer that you want to display the reversed view in real-time.
I would create a custom SurfaceView and override the onDraw method to split the image in two and reverse the two slices.
Then I would pass the holder of your surface to the camera object like this:
camera.setPreviewDisplay(myCustomSurfaceView.getHolder());
What about simply drawing only half your image at a time?
Create a custom component and override the onDraw. When you draw your bitmap, simply adjust the location and width values so you are only drawing half of the image at a time... of course you will need to draw twice.
You could also do the same thing with a second bitmap.. apply only part of your original bitmap to the second bitmap and do that twice, adjusting the location and width as needed.
Other options are to do some sort of transform, but my guess in the end is that your going to be doing something similar.
Related
Can not make a bitmap from a complicated view with state machine.
I have a RelativeLayout in which a dynamic tree of views handles touchevents to draw graphics. It uses a state machine to keep track of events like down, move and up and perform various drawing activities.
Now I want to make a copy (bitmap) of this RelativeLayout every time the view changes and display on the second screen. I have tried both methods I found online:
draw(theSecondCanvas);
Bitmap cache = getDrawingCache();
Both work most of time except occasional failure. The problem is both methods will eventually call every child views' draw() one more time to draw on the second canvas. But the state machine has changed to the different state based on the last touch event. It gives different drawing result or sometime error with null object reference because the additional drawing request has no touch event associated with it.
One option is for me to fix the complicated logic of state machine in the tree of views so it can handle an additional stateless drawing on the second canvas.
But I would think it has to be a simpler way to capture a bitmap from a view without drawing everything again. The view has done all the drawing inside already. It doesn't make sense to repeat the same work on the second canvas just to get a copy of bitmap.
Any suggestions? Thanks in advance!
I realized that off-screen rendering is not necessary in my case. I can intercept default canvas and draw on my own canvas with a bitmap. Then copy the bitmap to the default canvas. This solves the problem.
I'm trying to create a new view that would:
load an image
allow the user to zoom and rotate the image with two fingers while a "cropping box" stays translucent over the top while the image extends beyond the "cropping box"
with the end goal of being able to mark the rotation and position of the main image (so that later i could crop out or show the area within the cropping box)
I'm wondering if I can do this with an ImageView holding the image in the background and another ImageView holding the crop box on top of it, then using TouchEvents to move the image, would this work?
Or do I need to use some drawing API on a 2D surface?
I'm just really new to creating custom objects in Android that aren't just customized out-of-the-box Views.
What's the standard way of creating something like this?
Thanks!
Create a Compound View by extending RelativeLayout with two overlapping ImageViews in it. Then override onTouch event or override onGestureDetector interface in that newly created View.
Official Documentation: http://developer.android.com/guide/topics/ui/custom-components.html
Another Tutorial: http://www.vogella.com/tutorials/AndroidCustomViews/article.html
I'm trying to put corners im my ImageView and I find these "workarounds":
1 - Take the Bitmap soure and paint then
2 - put a second ImageView on my layout and use shape+corners as its source
It's not possible take the image view and put a corner around then?
In my app i have a List with a lot of ImageView (the Bitmap used in this ImageView's is programmatically) and I want to put corners in every ImageView.
There is any other option?
You can create a selector that contains shape with rounded corners, and then apply it as the ImageView's background using xml.
Look at this answers here
You can also do it via code by using PorterDuffXfermode. PorterDuffXfermode uses alpha compositing that will allow you to create and intersection (things of mathematical sets here) between the Canvas you get from onDraw() and an off screen Canvas you will have to create. You will use one of the PorterDuff.Mode flags to tell the framework you want to only render the pixels that intersect from the two Bitmaps in each Canvas.
More on Alpha Compositing
How should I create this custom View? The actual slider doesnt need to slide, it is set once programatically and then just stays in that position. I was thinking that even if I extended ProgressBar I would still need to do some maths in order for the arrow to appear directly over a notch, so maybe drawing each Rect onto a canvas and then the thumb above in the correct place would be a better approach? Thanks in advance
I need to capture more pixels than the width of the screen contains to save a higher res image. I figure the only two options are to pack more pixels into the screen with some Matrix command, or to make the actual view larger than the screen (which I don't think is possible.) I should probably make it known that I'm using OpenGL ES 2. Any help?
The technique you're looking for is called Render to Texture. Essentially you create an offscreen framebuffer, and redirect your draw calls to this framebuffer instead of the default.
You can make your framebuffer as big as you want (within hardware limitations).
This looks like a reasonable example:
http://blog.shayanjaved.com/2011/05/13/android-opengl-es-2-0-render-to-texture/