Android開発にはかなり新しいです。私は、キャプチャされたイメージを取得し、そのイメージをバックグラウンドとして設定できる単純なアプリを作っています。私はsetBackground(新しいBitmapDrawble ...)を使ってこれを行うことができました。私の次のアクティビティは、その背景と共にテキストビューを編集することでした。保存ボタンをオンにすると、編集されたテキストビューと背景の両方を表示できる次のアクティビティに進みます。ImageViewをビットマップに設定して次のアクティビティに送信
私の質問では、編集したテキストを表示できましたが、背景を表示できませんでした。ここに私の次のコードです。
RetrieveImage.Activity
public static final String EXTRA_MESSAGE = "com.example.hyunsukcirllee.footstep.MESSAGE";
private ImageView mdisplayBackground;
public static final int SEND_MESSAGE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retrieve_photo_background);
//Bundle to get intent
Bundle extras = getIntent().getExtras();
//If Bundle is not empty proceed
if(extras != null){
//get the imagepass key from the previous activity and set it to bitmap
Bitmap retrieveImage = (Bitmap) extras.get("imagepass");
//If the bitmap is not empty
if(retrieveImage != null){
//Set it to following imageView
mdisplayBackground = (ImageView) findViewById(R.id.background_captured);
mdisplayBackground.setBackground(new BitmapDrawable(getResources(), retrieveImage));
mdisplayBackground.getBackground().setAlpha(80);
}
}
}
//onClick Send button
public void sendMessage(View view){
//Creating an explicit intent to display the sent message
Intent footstep_intent = new Intent(this, DisplayMessageActivity.class);
//EditText Id
EditText editText = (EditText) findViewById(R.id.editText);
//User editText
String message = editText.getText().toString();
//This part is what I want to implement!!!
mdisplayBackground = (ImageView) findViewById(R.id.background_captured);
mdisplayBackground.buildDrawingCache();
Bitmap image_pass_again = mdisplayBackground.getDrawingCache();
//Put both Bitmap and String Message to the intent
footstep_intent.putExtra("Image", image_pass_again);
footstep_intent.putExtra(EXTRA_MESSAGE, message);
startActivity(footstep_intent);
}
}
画像とテキストの両方を表示する次のアクティビティ現在、送信ボタンをクリックした後に動作しないコードに続いて
private ImageView mdisplayBbackground;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
//if the intent has the name image do setbackground
if(getIntent().hasExtra("Image")) {
Bundle iimage = getIntent().getExtras();
Bitmap b = (Bitmap) iimage.get("image");
mdisplayBbackground = (ImageView) findViewById(R.id.background_capturedd);
mdisplayBbackground.setBackground(new BitmapDrawable(getResources(), b));
}
//if the intent contains the message-> view
if (getIntent().hasExtra(RetrievePhotoBackgroundActivity.EXTRA_MESSAGE)){
Intent footstep_intent = getIntent();
String message = footstep_intent.getStringExtra(RetrievePhotoBackgroundActivity.EXTRA_MESSAGE);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(message);
}
}
}
。上記のコードを使用してビットマップを渡してコンテンツURIに設定してみましたが、私が推測するコンセプトを正しく理解していませんでした。 "外部ストレージを使用してイメージファイルの直接パスを呼び出し、次のアクティビティ用にimageViewを設定する方法はありますか?" もう1つの質問は「Imはまだこの分野で練習しているので、コーディングの面でより良いフォーマットがあれば、フィードバックを得たい」 ありがとう!
あなたは、静的フィールドを使用することができますが、あなたは、すぐにそれがあるとして、ビットマップを再利用する必要があります不要になりました。アドバイスをいただきありがとうございます。 –