Android: How to select part of image? - android

In my application. There's section select block of apartment. In there a A and B block. So i want to choose A or B block from single image. Image is
There is what way to do this?

I guess you could use getLocationOnScreen()and hardcode the values you want. If user clicks on certain part of the image it prompts one response, if they click somewhere else it prompts another response. More info here Android: How do I get the x y coordinates within an image / ImageView?

Use BitMap concept. Convert full image as bitmap the crop the bitmap based on (x,y) positions.
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
Bitmap cropbitmap=Bitmap.createBitmap(bitmap, xpoint,ypoint,width, height);
//default android method createBitmap(Bitmap source, int x, int y, int width, int height)
other simple way use library like this from github
android-crop
uCrop
Android-Image-Cropper

Related

Crop a triangle from an image, using its center in android

How can I crop a triangle from an image (given the degree) using it's center.
for e.g. In the below image, fig_1 is the original image. I want to cut it like fig_2, fig_3 and fig_4 where, x, y and z are the degree of the angles.
Any help would be appreciated. Thanks.
Not sure if this is the best solution but you might want to use the BitMap class. First write the contents of the image to a Buffer, then use copyPixelsFromBuffer(Buffer) in BitMap class to get a BitMap. Then write the logic to edit the BitMap, e.g. you can use eraseColor(int). Then copy your edited BitMap to an ImageView using setImageBitMap(BitMap) method in ImageView class.

Android: Cropping an image to specific size

My intention is to have the user pick an image from the gallery, then have a cropping activity come up. However, I need the rectangle that defines the cropping mask to be locked to a certain dimension and then the user simply repositions it to display a portion of an image.
Any ideas on how this would be done?
Thanks
-T
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null)
.setType("image/*")
.putExtra("crop", "true")
.putExtra("aspectX", width)
.putExtra("aspectY", height)
.putExtra("outputX", width)
.putExtra("outputY", height)
.putExtra("scale", true)
.putExtra("scaleUpIfNeeded", true)
.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f))
.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
You need to create a custom ImageView class to achieve zooming and panning of an image and can have a fixed rectangle image(transparent) overlaying on this image. And can create sub-bitmap of that bitmap. and save it in a file.
createBitmap(Bitmap source, int x, int y, int width, int height);
This method is used to create a sub-bitmap.
http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
After achieving zooming and panning, I am not sure if createBitmap can create sub-bitmap from the visible portion of the image(i.e. part of image wont be visible on the screen when it is zoomed), So try getting the drawingCache() from imageView and create sub-bitmap for the same.

Crop to fixed portion of ImageView on Android

How do i get a part of a bitmap (which is in a imageview) saved as shown in the picture. All i need to do is to crop a particular image using (x,y) coordinates. all that i have is x,y coordinates and nothing else to select the cropped area. Between, user doesnt select the crop area. So its enough if its static. yellow part is an imageview(not the whole activity)
just create a new Bitmap and use the original one as the source.
Insert as x and y coordinates 0 and your custom width and hight.
public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height) .
This post describes how to get a Bitmap from a view, in your case the imageview you want to crop.
Converting a view to Bitmap without displaying it in Android?

Cutting the image in jigsaw shapes in android

I want to know how to cut an image in jigsaw form in android at run time. What i actually want is user can enter any image and then made puzzle of it.
Any API or method for doing this in android ?
Thanks in Advance.
You can use this method in Bitmap to cut it into a new BitMap of specified width and height pixels
starting from specified pixel location of x and y
public static Bitmap createBitmap (Bitmap source,
int x,
int y, int width, int height)
Assuming your puzzle piece is square, you can use createBitmap() function.
Returns an immutable bitmap from the specified subset of the source
bitmap. The new bitmap may be the same object as source, or a copy may
have been made. It is initialized with the same density as the
original bitmap.

How to get ROI of an image in Android

I have an image file (.jpg) which contains image like Face. From my application i want to capture that particular Face part and copy that part into a new bitmap file. I have a rectangular co-ordinates of that Face part, so how do i capture only Face part from the image file and copy that into a bitmap file??
Could any body help me to get rid of this problem....
Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) will do the creation. For save, read this: Save bitmap to location
You could use
bitmap1.getPixel(x,y)
on the source image and using
bitmap2.setPixel(x,y,color)
on the destination image.
There is also a respective
bitmap1.getPixels( pixelArray, offset, stride, x, y, width, height)
which is undoubtedly faster.

Categories

Resources