2011-07-22 12 views
2

私はカメラの電話で画像を撮るアンドロイドアプリケーションを持っています。画像をImageViewに入れてください。次に画像の下部にテキストを設定します。 uは私を助けてください、私は次の何をすべき私に言うことができますいくつかのコードがいいだろうImageViewにテキストを設定します

ImageView image; 
    bitmap = android.provider.MediaStore.Images.Media 
         .getBitmap(cr, selectedImage); 
    image.setImageBitmap(bitmap); 

:?

今まで私のような何かをやりました!

EDIT:XML

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:weightSum="1"> 
<Button 
android:id="@+id/logoButton" 
android:layout_height="wrap_content" 
android:text="LogoButton" 
android:layout_marginLeft="40dip" 
android:layout_width="224dp"> 
</Button> 

<ImageView 
android:id="@+id/imageview" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"> 
</ImageView> 

UPDATE:

....onCreate(){ 
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
     File image=new File(Environment.getExternalStorageDirectory(),"PhotoContest.jpg"); 
     camera.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(image)); 
     imageUri=Uri.fromFile(image); 
     startActivityForResult(camera,1); 
         } 

public void onActivityResult(int requestCode, int resultCode, Intent data){ 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode){ 

    case 1: 
     if (resultCode == Activity.RESULT_OK) { 
       Uri selectedImage = imageUri; 
       getContentResolver().notifyChange(selectedImage, null); 
       image= (ImageView) findViewById(R.id.imageview); 
       ContentResolver cr = getContentResolver(); 
       Bitmap bitmap; 
       try { 
        bitmap = android.provider.MediaStore.Images.Media 
        .getBitmap(cr, selectedImage); 
        image.setImageBitmap(bitmap); 
        Toast.makeText(this, selectedImage.toString(), 
          Toast.LENGTH_LONG).show(); 
       } catch (Exception e) { 
        Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT) 
          .show(); 
        Log.e("Camera", e.toString()); 
       } 
      } 
     else 

     if(resultCode == Activity.RESULT_CANCELED) { 
       Toast.makeText(EditPhoto.this, "Picture could not be taken.", Toast.LENGTH_SHORT).show(); 
      } 
     } 
} 

1.I'mはわからないでframeLayoutと、このトリックは、テキストを置くこと:これは私がカメラを使用する方法であります私のイメージ上に...さらに私は写真をアップロードしたいので。私はウェブサイト上の写真をアップロードする場合テキストがまだそこにある???

2.私は写真を撮った後、それを水平に表示し、フルスクリーンでは表示しません。>私はそれをどのように修正できるか知っていますか?

+0

を私はXML.I'm任意のヌル例外を取得していないを持っています! – adrian

+0

私は自分の質問をXMLで編集しました。だから次は? – adrian

+0

@george ImageViewの代わりにカメラのプレビューを直接見たいという私の答えを編集しました – Shlublu

答えて

3

あなたは絵で作られた新しい画像+テキストoverpritedを構築したり、画面上の層としての両方を表示することができます。これは、このイメージを保存して再利用するかどうかによって異なります。

私はあなたの質問を理解していたので、これはここでは当てはまりません(私が間違っている場合は教えてください)。だから、FrameLayoutはあなたの友達です:それはオーバープリントフレームとしてグラフィカル要素を示すことができます:

<?xml version="1.0" encoding="UTF-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView ...your picture, with the desired attributes /> 
    <TextView ...your text, with the desired attributes /> 

</FrameLayout> 

あなたは彼らがそのようなボタンなど、など、他の部品が付属して作るためにLinearLayout秒でImageViewTextViewを囲むことができますだけで、あなたが持っていますFrameLayoutに直接含まれる各コンポーネントを、通常のレイアウトとして設計できる新しいフレームと見なします。このページのxevincentの答えにあなたのコメントにさらに

代わりに、あなたのカメラのプレビューを表示したいImageViewの、あなたはCameraのライフサイクルの世話をすることSurfaceView独自に定義することができる場合:

package com.example; 

// imports 

public class CameraView extends SurfaceView implements SurfaceHolder.Callback { 

    public CameraView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     initializeSurfaceHolder(); 
    } 

    public void surfaceCreated(SurfaceHolder holder) { 
     // call Camera.open(); and Camera.setPreviewDisplay(holder); here 
    } 

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
     // Call Camera.setParameters() and Camera.startPreview() here 
    } 

    public void surfaceDestroyed(SurfaceHolder holder) { 
     // Call Camera.stopPreview() and Camera.release() here 
    } 

    private void initializeSurfaceHolder() { 
     // This initializes the SUrfaceHolder of your Camera 
     final SurfaceHolder holder = getHolder(); 

     holder.addCallback(this); 
     holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
    } 
} 

そして、あなたのレイアウトでこのクラスを使用します。もちろん

<?xml version="1.0" encoding="UTF-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.example.CameraView   
     android:id="@+id/previewcam" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

    <TextView ...your text, also with the desired attributes /> 

</FrameLayout> 
+0

私の更新を見てください! – adrian

+0

はい、私はそれにテキストとこのイメージを保存したいと思います!!! – adrian

1

あなたはFrameLayoutを使用して、あなたのレイアウトではそれに応じて

0

をあなたの画像やテキストを配置、向き垂直でImageViewのとのTextViewを作成してのTextViewのテキストを設定することができます!

0

このlinkはレイアウトのトリックですが、例によって正確に表示されます。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:scaleType="center" 
    android:src="@drawable/golden_gate" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dip" 
    android:layout_gravity="center_horizontal|bottom" 

    android:padding="12dip" 

    android:background="#AA000000" 
    android:textColor="#ffffffff" 

    android:text="Golden Gate" /> 

</FrameLayout> 
+0

はい、ImageViewがカメラから来ているのは何か描画可能ではありません;) – adrian

関連する問題