當沒有將任何位圖傳遞給下一個活動時,該意圖起作用。但是,當我試圖發送編輯位圖到下一個意圖,當我點擊'下一步'按鈕沒有任何反應。任何善良的人願意幫助我呢?通過意向發送位圖到下一個活動
package com.example.cklim.opencv_test2;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
Bitmap bitmap;
Button next;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout l1= new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
next = new Button(this);
next.setText("next");
next.setBackgroundColor(Color.BLACK);
next.setTextColor(Color.WHITE);
next.setLayoutParams(params);
l1.addView(next);
l1.addView(new deleteView(this));
setContentView(l1);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,display.class);
i.putExtra("BitmapImage", bitmap);
startActivity(i);
}
});
}
class deleteView extends View {
// initial variables
int xLoc,yLoc,r = 0;
Paint p;
Canvas pcanvas;
public deleteView(Context context) {
super(context);
setFocusable(true);
// sets to transparent whenever user touches any location of image
setBackgroundColor(Color.TRANSPARENT);
// sets the paint
p = new Paint();
p.setAlpha(0);
// image processing with DST_in mode
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
p.setAntiAlias(true);
// get phone display's details
Resources r = this.getContext().getResources();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
//get the height and width
int h = Math.round(metrics.heightPixels*7/8);
int w = metrics.widthPixels;
// getting image from resources *************** this is where the image goes in
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.dog_back);
// create the bitmap to fit the phone's display
bm = Bitmap.createScaledBitmap(bm, w, h, true);
// creates a mutable bitmap with the exact height and width
bitmap = bm.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
pcanvas = new Canvas();
pcanvas.setBitmap(bitmap);
pcanvas.drawBitmap(bm, 0, 0, null);
}
// method called whenever user's finger touches the image
@Override
protected void onDraw(Canvas canvas) {
// cricle drawn to erase specific region
pcanvas.drawCircle(xLoc, yLoc, r, p);
canvas.drawBitmap(bitmap, 0, 0, null);
super.onDraw(canvas);
}
// handles on touch events
@Override
public boolean onTouchEvent(MotionEvent event) {
// radius size of circle
r =80;
// gets the touched location of x and y
xLoc = (int) event.getX();
yLoc = (int) event.getY();
//invalidate the canvas
invalidate();
return true;
}
}
}
接收器意圖的Java類如下:這裏
package com.example.cklim.opencv_test2;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
public class display extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
ImageView imageView = (ImageView)findViewById(R.id.imageView);
Intent i = getIntent();
Bitmap bitmap = (Bitmap) i.getParcelableExtra("BitmapImage");
//BitmapDrawable ob = new BitmapDrawable(getResources(), bitmap)
imageView.setImageBitmap(bitmap);
}
}
任何人有任何想法出了什麼錯我的編碼?實際上,我試圖從圖像中刪除不需要的區域,並嘗試將編輯後的圖像發送到下一個意圖進行進一步處理(疊加到另一個圖像上)。希望我已經解釋清楚了。幫助確實值得歡迎!
檢查您的logcat的錯誤 – Buddy
這是我打'下一步'按鈕時唯一的錯誤:01-01 23:52:04.651 27548-27548/com.example.cklim.opencv_test2 E/JavaBinder:!!!失敗的粘合劑交易!!!顯而易見,當我實現正常的意圖而不傳遞位圖圖像時,它工作得很好。但是當我傳入位圖時,當我點擊'nect'按鈕時,意圖不起作用或者沒有響應@Buddy – user5713341
你從哪裏找到這個示例? –