Adding overlay image at drag position on a final bitmap - Android

Basic description of what I'm trying to do: Load up a background image, paint some text into a new bitmap layer, position that text over the background image where I want it to show up, then save the background image with the new layer on top of it where I had positioned it.

Problem: The problem I'm having is that when I paint the text over the background image it ends up in the wrong x/y position.

For example: 1. I load in a 640x480 image with the ScaleType set to Fit_Start (which shrinks it to 1/2 the size). I'm keeping track of the ratio and using it when painting the text to the final image.

  1. Then I create a blank overlay bitmap, paint some text onto it, trim the extra transparent space off, and place it into another imageview (ScaleType of Matrix)

  2. Then I position that new imageview using my mouse and the onTouchEvent method. I keep track of the X and Y:

    float X = event.getX();

    float Y = event.getY() - 50; // Title bar, status bar

    overlayView.layout((int)X, (int)Y, overlay.getWidth() + (int)X, overlay.getHeight() + (int)Y);

  3. Then I attempt to write the text to the final image (background image) using the X & Y except that I double the X & Y since I know that the image was shrunk in half to fit the screen.

  4. Final result is the text being written to the wrong location. It ends up being slightly too much X and not enough Y (like 25+ depending on the background image scale -- this varies).

Somewhere my math is wrong or I'm forgetting to add something into the formula for calculating the correct position on the background where the text should be painted to. I've been working on this for quite a few hours and haven't been able to pin-pointed the problem.

The last thing I tried was to take into account the title bar and status bar, which on the simulator takes up like 50 pixels. So, I'm subtracting that from Y, which is done when dragging. But that still doesn't correct Y being off different amounts depending on the background image dimensions.

Anyone have any ideas on what I'm doing wrong?

Asked by: Chloe686 | Posted: 20-01-2022

Answer 1

i don't think that is your problem yet, but i think you need to account for device density. Cause title bar + status bar not gonna be 50 px it's 50 dip

Answered by: Sam248 | Posted: 21-02-2022

Similar questions

android - How to set image overlay on another image on specified X and Y position on main image?

how to set small images on main image in specified x and y position , my main image also zoom functionality so if user zoom image than the another all image also set specified x and y position as per zoom level. please any one suggest which step follow for this ....

android - Remove overlay with position

I want to remove same overlay at the specific position. This is my code for add the overlay, but how can get the position for every overlay? public void visual_overlay(List<DatiOverlay> list_overlay){ CustomOverlay itemized_overlays = null; GeoPoint point = null; for(int ov=0;ov<list_overlay.size();ov++){ itemized_overlays = new CustomOverlay(drawable,mappa, Integer.toString(lis...

android - Position view below action bar with overlay

I would like to position a view below an action bar with overlay. Is there a way of doing this via XML layout? I would like to avoid using constants as there are already at least 4 possible values and that number is likel...

overlay - Android position view

In an application I have a relative layout with some content. What I need is to position a button over this content in such a way that it would always be stacked to the bottom of the display and in the center of its bottom border. Can someone give any suggestions of how to do that?

android - How to cut some part of bitmap and overlay it in the fixed position

`Bitmap cut = Bitmap.createBitmap(bitmap, 150, 150, 100,100); ` How to put in the fixed position ?

android - Scale and position in bitmap overlay

I am working on a screen that allows user to drag and drop one image onto another. After that the code should be able to redisplay the resulting image. I am having a hard time making the reddit image normal size. More details about it is in bold next to screen 3 below. Note: all of my images so far are in the res/drawable folder. Screen 1: Initial screen:

android - Position an Image View as Overlay Image on Camera Preview

Hello There I am coding a Camera App using Android Camera API! It has the following functions: The app has an image view over the camera preview The user can drag and drop that image view on the camera preview The drop event catch the position of the image view where it dropped The user captures an image and the image view is being added on the photo on the user's desired dr...

android - Position an Overlay Image onto Canvas

Hello There I am working on an Android Application that takes an Image from the gallery and add a watermarks on it. It has the following features: The Screen is manually locked to portrait mode by me in manifest.xml The user can drag the water mark to any desired location on the screen The water mark image is being added on the user's image The user can save the ima...

How to change position of Toast in Android?

When I use Toast to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position. Now I want to display it in the middle of screen or somewhere according to my choice. Can anyone guide me how to achieve this?

android - Setting the position within a spinner

Good Afternoon, I have a spinner array containing 3 spinners. Each spinner is populated via a res string array. Each array contains the numbers 1-100. When the activity starts each spinner contains a string array of 1-100 and when you click on a spinner the first choice is 1. Say a user picks 25 on the first spinner. I'd like the 2nd spinner to show 25 as the starting point for scrolling when the spinner...

gps - Android Position reset after Restart? -> Serious Problem

is it possible, that android cleares the last known location after a restart? Yesterday my code worked very fine, but today after rebooting my phone (AND emulator) it seems that the .getLastKnownLocation (see below) returns null, which leads to a nullPointerException... Can you confirm that? How can I avoid this problem? I'm desperately searching for an answer lm = (LocationManager) getSystemService(Context...

How to get an item's position from item's ID in android spinner?

I need to get an item's position in spinner knowing it's ID. I've tried to do it with Spinner and SpinnerAdapter classes but there are no corresponding methods there. Thanks, Aleksander

android - auto adjust the size and position of edittext and button

In emulator, size of edittext and button looks nice but in motorola milestones, both of them are so small. I think there are different types of screen layout. Is it possible to adjust the size automatically? My xml is below : <?xml version="1.0" encoding="utf-8"?><RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="

android - Position views at specific location?

Is there a way to place widgets / views on the screen at any specific position required? Something like a calendar with daily events that could overlap. e.g. if every hour in a day is represented by 1 hour and there are 2 appointments that overlap partially (say 12:00 - 12:30 and 12:20 - 01:00) this would be drawn in the same row but the 12:20 one positioned slightly below the first. Also there may be views...

android - Change Video position while playback

Is there any way on Android to dynamically change position of VideoView or SurfaceView while playing video? I've tried to use view animators, Surface.setPosition(), View.layout(), push Surface view with ralated LinearLayout with bigger weight( this approach helps sometimes and i see that video jumps to new position while playing but i need smooth moving.) and nothing happens until video ends. (Checked on Emulat...

android - How to position item of ListView?

I have a ListView with number of items. I'd like to place the item being clicked in the top of the screen. i am trying to use requestChildRectangleOnScreen of ListView that seems to do the job, however I cannot figure out how to properly specify the rectangle param. Any suggestion and/or code sample will be really helpful Thanks a lot

android - Change Button position

I have a button in an AbsoluteLayout and I want to change the X and Y position on screen programmatically. How do i it?

layout - Button position in android

I'm trying to make some "Chat view" with speech bubbles like on the SMS iPhone app. This is a row I have done in the xml editor : But when I launch my application, I get this : http://img59.imageshack....

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android