I have a very wide video that I am trying to crop a part of in the display and I was trying to find a method of perhaps taking a bitmap of the native resolution of that video and then doing what I like with that (i.e. move the video from side to side). I want to be able to watch the resized images placed on the screen as if the video is cropped. I imagine this would be done with something like getDrawingCache but I'm not getting the full resolution I'm looking for. Does anyone know a way around this?
Edit: I have found the latest source file for the videoview so I am going to see how well editing that will work
You can simply render the video on a surface larger than the actual display, and then manipulate the position and cropping of this view.
Related
I am working on camera2 api and sometime getting blur images while capturing images from camera. I need to check if clicked image is blur or not, Using openCV increase the .apk size 3x times. I also check the solution posted on a SO thread Here but seems incomplete.
Is it possible to detect if image is blur or not using MLKit? Any suggestion is appreciated. Thanks.
I have tried writing my own code for accessing camera via the camera2 API on Android instead of using the Google's example. On one hand, I've wasted way too much time understanding what exactly is going on, but on the other hand, I have noticed something quite weird:
I want the camera to produce vertical images. However, despite the fact that the ImageReader is initialized with height larger than width, the Image that I get in the onCaptureCompleted has the same size, except it is rotated 90 degrees. I was struggling trying to understand my mistake, so I went exploring Google's code. And what I have found is that their images are rotated 90 degrees as well! They compensate for that by setting a JPEG_ORIENTATION key in the CaptureRequestBuilder (if you comment that single line, the images that get saved will be rotated). This is unrelated to device orientation - in my case, screen rotation is disabled for the app entirely.
The problem is that for the purposes of the app I am making I need a non-compressed precise data from camera, so since JPEG a) compresses images b) with losses, I cannot use it. Instead I use the YUV_420_888 format which I later convert to a Bitmap. But while the JPEG_ORIENTATION flag can fix the orientation for JPEG images, it seems to do nothing for YUV ones. So how do I get the images to be correctly rotated?
One obvious solution is to rotate the resulting Bitmap, but I'm unsure what angle should I rotate it by on different devices. And more importantly, what causes such strange behavior?
Update: rotating the Bitmap and scaling it to proper size takes way too much time for the preview (the context is as follows: I need both high-res images from camera to process and a downscaled version of these same images in preview. Let's just say I'm making something similar to QR code recognition). I have even tried using RenderScripts to manipulate the image efficiently, but this is still too long. Also, I've read here that when I set multiple output surfaces simultaneously, the same resolution will be used for all of them, which is quite bad for me.
Android stores every image, no matter if it is taken in landscape or in portrait, in landscape mode. It also stores metadata that tells you if the image should be displayed in portrait or landscape.
If you don'r turn the image according to the metadata, you will end up with every image in landscape. I had that problem too (but I wanted compression so my solution doesn't work for you).
You need to read the metadata and turn it accordingly.
I hope this helps at least a bit.
How do I compress a bitmap to a video file with android. Like, adding the bitmap file to the video. I have a .png file which I decoded into a bitmap. Now, I want to add that bitmap to a video file so that when the video plays it also show the bitmap I added
If you just want to display the bitmap on top of the video when it is playing on your Android device, then the easiest thing is to display it in a separate view on top of the video, using a relative layout in your layout file, for example. This avoid CPU and battery consuming video manipulation.
If you actually want to add the image to the video so it is saved then one way to do this on Android is to use ffmpeg. There are several ways to use ffmpeg but one of the easier ones is to use a well supported ffmopeg wrapper, e.g.:
https://github.com/WritingMinds/ffmpeg-android-java
This allows you use the standard command line syntax for the ffmpeg instructions themselves, which you will find is well documented and supported on the web. For example, the following covers adding an image into a video:
https://ffmpeg.org/ffmpeg.html (look for ' overlay an image' near the bottom)
Note that adding the image is processing intensive, so you may quite likely find your device is not able to do this in real time - i.e. not able to add it while you are watching. If you have the luxury of being able to add the image first to the video and then watch it, then this may be more practical - you could even consider doing it on the server side after uploading the video, where you should have much more processing power.
If you must see the image and the video in real time then you may find a combination of the above approaches works for you - simply display the image over the video in realtime, and then add the image to the video afterwards before storing it.
I am new to Android and I having troubles setting a dynamic background just like Tumblr login UI,
The link below is where I got some help.
Set Animated .GIF As Background Android
But it only works when I load small-size animation, or I have to drop lots of frames of a GIF animation which leads to incoherence.
If I load all the frames which will cause OutOfMemoryError, I don't think it's the right way.
Is tumblr uses GIF animation or it's actually a short video?
I know that Twitter converts all GIFs to MP4. Video compression is far better than GIFs leading to smoother playback and reduced bandwidth and happy users :) Is using MP4s an option?
More on the subject here.
Not sure how long your animation is, or how high res its frames are, but you probably need to look at loading the image frames in scaled down form into memory. The Android docs give a very coherent explanation of how to do this here (basically, you first find the res of the bitmap, then load a scaled down version of it appropriate to the device's screen resolution). It may also be that the animation is too long, and you need to look at forcing bitmaps to recycle (using bitmap.recycle()) once displayed.
I've been struggling for a long time with large images that are able to zoom. I am loading some picture from the network that can have very variable size: it might go from 0.5MP up to 10MP. Simply loading one to a bitmap can produce application crash because of OOM exception. But details are very important so I want the user to be able to zoom on them such that full quality is maintained (so the picture should refine itself during zooming). I don't find a proper way to do this. I've used the TouchImageView library, but it doesn't manage large pictures at all. If I first down sample my picture with the inSampleSize parameter of the BitmapFactory, I lose the quality definitively. I don't want to code a whole new zooming tool, as it is already implemented on every android phone in the default Gallery app. There has to be a way to use this kind of tool, and simply display a large image that is able to zoom, right?
Have you tried PhotoView?
You could also do it with loadUrl(String) of standard WebView which should handle big images too. WebView has built-in zoom controls.
BitmapRegionDecoder(added in 2.3.3) may work. But I've not tried it.
It seems that the implementation in Gallery is OpenGL, there is no way to use it simply.