Note that there are some explanatory texts on larger screens.

plurals
  1. POOverlay image on top of another image
    text
    copied!<p>I am doing a photo editing function that kinda works like a water mark.</p> <p>The user selects the image A. After the image is selected, the user can select another image B to populate on top of the image A and they can move the image B around while image A is still static at the back.</p> <p>After the placement of image B is done, the user can merge both image into one and save it as a <strong>single image</strong>. </p> <p>I got the movement of image B function done but i am not sure how to actually combine the two images together.</p> <p><strong>Edit 1:</strong> I want them to be either taken from the camera or gallery then combine the two images, B over A and save it to SD Card </p> <p><strong>Edit 2:</strong> This is what i did to make the image B to move around my view. Now all i need is to connect the image b to the main image (which is in the background) and save it as a SD card. Is there a way to actually integrate both imageviews and its custom position (image B) and create a bitmap that can be saved to the sd card.</p> <pre><code>private ImageView img_additionalImage; float x, y = 0.0f; boolean isImageMoving = false; img_additionalImage = (ImageView) findViewById(R.id.img_additionalImage); img_additionalImage.setOnTouchListener(new OnTouchListener() { @SuppressLint("NewApi") @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: isImageMoving = true; break; case MotionEvent.ACTION_MOVE: if (isImageMoving) { x = event.getRawX() - img_additionalImage.getWidth() / 2; y = event.getRawY() - img_additionalImage.getHeight() / 2; img_additionalImage.setX(x); img_additionalImage.setY(y); } break; case MotionEvent.ACTION_UP: isImageMoving = false; break; } return true; } }); </code></pre> <p><strong>Edit 3:</strong> This is the code that gives me nullpointer when i call this.</p> <p>MainActivity</p> <pre><code>CombineImages combineImages = new CombineImages(MainActivity.this); img_additionalImage = (ImageView) findViewById(R.id.img_additionalImage); combineImages.combine(img_additionalImage); </code></pre> <p>The CombineImages class is what you have provided.</p> <pre><code>12-31 20:54:33.470: E/AndroidRuntime(6330): FATAL EXCEPTION: main 12-31 20:54:33.470: E/AndroidRuntime(6330): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.photosharingtest2/com.example.photosharingtest2.MainActivity}: java.lang.NullPointerException 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread.access$600(ActivityThread.java:140) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.os.Handler.dispatchMessage(Handler.java:99) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.os.Looper.loop(Looper.java:137) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread.main(ActivityThread.java:4898) 12-31 20:54:33.470: E/AndroidRuntime(6330): at java.lang.reflect.Method.invokeNative(Native Method) 12-31 20:54:33.470: E/AndroidRuntime(6330): at java.lang.reflect.Method.invoke(Method.java:511) 12-31 20:54:33.470: E/AndroidRuntime(6330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 12-31 20:54:33.470: E/AndroidRuntime(6330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 12-31 20:54:33.470: E/AndroidRuntime(6330): at dalvik.system.NativeStart.main(Native Method) 12-31 20:54:33.470: E/AndroidRuntime(6330): Caused by: java.lang.NullPointerException 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.content.ContextWrapper.getResources(ContextWrapper.java:81) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.view.View.&lt;init&gt;(View.java:3314) 12-31 20:54:33.470: E/AndroidRuntime(6330): at com.example.photosharingtest2.CombineImages.&lt;init&gt;(CombineImages.java:27) 12-31 20:54:33.470: E/AndroidRuntime(6330): at com.example.photosharingtest2.MainActivity.&lt;init&gt;(MainActivity.java:39) 12-31 20:54:33.470: E/AndroidRuntime(6330): at java.lang.Class.newInstanceImpl(Native Method) 12-31 20:54:33.470: E/AndroidRuntime(6330): at java.lang.Class.newInstance(Class.java:1319) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.Instrumentation.newActivity(Instrumentation.java:1057) 12-31 20:54:33.470: E/AndroidRuntime(6330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015) 12-31 20:54:33.470: E/AndroidRuntime(6330): ... 11 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload