Android java create new tiled bitmap from existing bitmap - java

OK so here is what I'm looking to do. I have an app that loads small bitmap images with a pattern that I'd like to use as my phones background (not the app background) Problem is when I set it as a wallpaper now using wallpapermanager it stretches the image and it looks horrible. Is there anyway I can either a) using wallpaper manager to tile the image so it looks nice or b) create another tiled bitmap from the small bitmap and use that. Suggestions?

find the dimensions of your screen. Edit the picture using http://pixlr.com/editor/ if you dont have photoshop.

Related

Drawing contour on biggest rectangle in an image using opencv

I have a activity in my android app which is receiving a bitmap from previous activity through intent. In the image view of the current activity I want to display that bitmap along with the contour on largest rectangle or square found in the bitmap and the contour should be adjustable so that I can adjust it in case its not correct and then when I click ok it should perform a 4 point perspective transformation on the bitmap and display it in the same image view. I searched through web a lot but I could not find what I was looking for.
This is the result I want:
How can I achieve this in opencv java android studio. I am new to opencv so I don't have even a slightest idea about how can I do that and where should I start.
Thank you.

BItmap appears to be rotated after rendering to imageview android camera api ndk?

I am trying to learn how to use ndk and renderscript. This is what i tried so far. I am using renderscript to convert nv21 frame to rgb. After that, i am getting the pixels from the rgb and sending the pixels to the ndk script to convert to grayscale. Then i created a bitmap from the grayscale pixels and i am rendering the bitmap to the imageview. Things seem to be working fine. However, I am facing an issue. When the preview is rendered in the imageview, the bitmap appears to be rotated. What could i be doing wrong ?
The NV21 frame received from the camera on most phones is always in landscape (see CameraInfo.orientation.
I tried rotating the imageview but then the grayscale effect disappears
Please show your code, there is some easy typo probably

Android: calling BitmapFactory.decodeResource() returns null

Im making an app where I need to create lots of similar images made out of simple components images. The images don't change but I don't want to have to make all of the images by hand (and I think it could be useful later to have them procedurally generated). As a basic example of what I'm trying to do I have 2 drawables and am trying to combine them on a Canvas. The issue is that when I create the canvas like so:
Canvas canvas = new canvas(background);
The app crashes because background is null. I Don't understand why background is null.
Here is the rest of the code:
Bitmap background = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.background);
Bitmap foreground = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.foreground);
Canvas canvas = new Canvas(background);
canvas.drawBitmap(foreground,0,0,null);
If it's of any help this is all in a fragment.

ImageView doesn't stretch image properly

So I have no clue why this is happening. I am using Universal Image Loader to load these images. It seems like the last line of pixels is being streched for some weird reason. I want the image to just stretch out evenly. (I don't care that it will look weird. The images below are for demo purposes.)
Also, don't mind the first and last image. I purposely blurred that out because it had someone's face on it.
This is how I set up my Universal Image Loader:
//setup Image Loader for loading cruise line logos
displayImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)//show this image when image is loading
.showImageForEmptyUri(R.drawable.ic_launcher)//show this image incase image doesn't exist
.showImageOnFail(R.drawable.ic_launcher)//show this image if fetching image from URL didn't work
.cacheInMemory(true)//cache image in RAM
.cacheOnDisc(true)//cache image in device for later use
.considerExifParams(true)
.displayer(new RoundedBitmapDisplayer(5))//super subtle rounded corners on images
.build();
This is caused by the way RoundedBitmapDisplayer draws the bitmap.
If you look at the source, you'll see that it uses a RoundedDrawable, which uses canvas.drawRoundRect() to draw a rounded rectangle of the desired size of the Drawable, using the downloaded image as the texture via a BitmapShader. BitmapShader does not support scaling (only clamping and tile modes). Try using a SimpleBitmapDisplayer instead which uses the normal ImageView.setImageBitmap() way of displaying the image.
If you need rounded corners, you'll have to find a different way to implement that, for example by scaling the Bitmap to the desired size first. Another option is to call Canvas.saveLayer() before delegating to BitmapDrawable for the scaling, and then applying the rounded corner masking effect using PorterDuff.Mode.DST_IN. Either way you'll end up writing a bit more low-level code, but you should be able to encapsulate everything nicely in a custom BitmapDisplayer.

Crop custom shape from photo

I need to have an Android app with ImageView on the screen and user should be able to draw a custom (closed) shape (something like a circle/ellipse) made of curves to select an object on the image. The shape then has to be saved to String (like M123,21L23,30C100,29...). Does anybody know how to achieve this ? Or just point me the right direction. Thanks
If you just want to draw another bitmap on your ImageView and it shouldn't be dynamic, than use AbsoluteLayout and position them above each other.
If it should be much more dynamic, I recommend to use a SurfaceView. A tutorial can be found here: Custome Shape from Photo

Categories