我正在做一个有点像水印的照片编辑功能。
用户选择图像A。选择图像后,用户可以选择另一个图像B来填充图像A的顶部,他们可以移动图像B,而图像A在后面仍然是静止的。
完成图像 B 的放置后,用户可以将两个图像合并为一个图像并将其保存为单个图像。
我完成了图像 B 功能的移动,但我不确定如何将这两个图像实际组合在一起。
编辑1: 我希望它们是从相机或画廊中拍摄的,然后将两个图像组合在一起,B over A 并将其保存到 SD 卡
编辑 2: 这就是我所做的让图像 B 在我的视图中移动。现在我只需要将图像 b 连接到主图像(在背景中)并将其保存为 SD 卡。有没有办法实际集成图像视图及其自定义位置(图像 B)并创建可以保存到 sd 卡的位图。
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;
}
});
编辑 3: 这是当我调用它时给我空指针的代码。
主要活动
CombineImages combineImages = new CombineImages(MainActivity.this);
img_additionalImage = (ImageView) findViewById(R.id.img_additionalImage);
combineImages.combine(img_additionalImage);
CombineImages 类是您提供的。
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.<init>(View.java:3314)
12-31 20:54:33.470: E/AndroidRuntime(6330): at com.example.photosharingtest2.CombineImages.<init>(CombineImages.java:27)
12-31 20:54:33.470: E/AndroidRuntime(6330): at com.example.photosharingtest2.MainActivity.<init>(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