Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

In this page you can find the example usage for android.widget ImageView setImageBitmap.

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.surveyorexpert.TalkToMe.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.talk_main);/*from   w  w  w.  ja v  a 2  s  . co m*/

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String online = preferences.getString("ONLINE", "");
    if (!online.equalsIgnoreCase("")) {
        ONLINE = online;
    }
    String PhotoPath = preferences.getString("PhotoPath", "");
    if (!PhotoPath.equalsIgnoreCase("")) {
        mPhotoPath = PhotoPath;
    }
    String ServerPhotoPath = preferences.getString("ServerPhotoPath", "");
    if (!ServerPhotoPath.equalsIgnoreCase("")) {
        mServerPhotoPath = ServerPhotoPath;
    }

    setTitle("mServerPhotoPath  " + mServerPhotoPath);

    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        domain = extras.getString("domain");
        project = extras.getString("project");
        resource = extras.getString("resource");
        nbcMarker = extras.getString("nbcMarker");
        nbcDescription = extras.getString("nbcDescription");
        userName = extras.getString("userName");
        user_id = extras.getString("user_id");
        severity = extras.getString("severity");
        costEst = extras.getString("costEst");
        version = extras.getString("version");
        strLongitude = extras.getString("strLongitude");
        strLatitude = extras.getString("strLatitude");
        section = extras.getString("section");
        element = extras.getString("element");
        childPos = ""; //extras.getString("childPos");
        parentPos = ""; //extras.getString("parentPos");            
    }

    //     File imgFile = new  File("/sdcard/Images/test_image.jpg");
    //  File imgFile = new  File("/storage/emulated/0/1405349215602.jpg");
    String path = Environment.getExternalStorageDirectory() + "/DCIM/Camera/1405349215602.jpg";

    /*
      Toast.makeText(TalkToMe.this,
      "mServerPhotoPath =  " + mServerPhotoPath
        , Toast.LENGTH_LONG).show();
      */

    /*
    Toast.makeText(getBaseContext(),
      "mPhotoPath =  " + mPhotoPath, 
      "mServerPhotoPath =  " + mServerPhotoPath, 
       Toast.LENGTH_LONG).show(); 
       */

    File imgFile = new File(mPhotoPath);

    if (imgFile.exists()) {
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        ImageView myImage = (ImageView) findViewById(R.id.finalImg);
        myImage.setImageBitmap(myBitmap);
        //         Toast.makeText(getBaseContext(),"Set File " , Toast.LENGTH_LONG).show(); 
    } else {
        Toast.makeText(getBaseContext(), "Not found " + imgFile.getName(), Toast.LENGTH_LONG).show();
    }

    speak = (Button) findViewById(R.id.bt_speak);
    speak.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendRecognizeIntent();
        }
    });
    speak.setEnabled(false);

    confirm = (Button) findViewById(R.id.btWriteToServer);
    confirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new PostComment().execute();

            Toast.makeText(getBaseContext(),
                    "TalkToMe Send to Server : " + "\nmPhotoPath : " + mPhotoPath + "\nsection : " + section
                            + "\nelement : " + element + "\ngotMessage : " + gotMessage + "\ndomain : " + domain
                            + "\nproject : " + project + "\nresource : " + resource + "\nnbcMarker : "
                            + nbcMarker + "\nnbcDescription : " + nbcDescription + "\nuserName : " + userName
                            + "\nuser_id : " + user_id + "\nseverity : " + severity + "\ncostEst : " + costEst
                            + "\nversion : " + version + "\nstrLongitude : " + strLongitude + "\nstrLatitude : "
                            + strLatitude,
                    Toast.LENGTH_LONG).show();

        }
    });
    //  confirm.setEnabled(false);

    result = (TextView) findViewById(R.id.tv_result);
    //   message = (TextView)findViewById(R.id.tvTalkMessage);
    //    message.setText(mServerPhotoPath);      
    tts = new TextToSpeech(this, this);
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ExpandImageFragment.java

/**
 * Initializes the UI of the fragment.//from   w  ww .ja va 2 s.co  m
 */
@Override
public void onStart() {
    super.onStart();
    ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setMessage("Downloading Image");
    ImageView imageView = (ImageView) getView().findViewById(R.id.expanded_image);
    final Bitmap image = CacheManager.getInstance().deserializeImage(id);
    if (image == null) {
        // Start the image getter thread.
        ThreadManager.startGetImage(id, imageView, dialog);
    } else {
        imageView.setImageBitmap(image);
        ThreadManager.startGetImage(id, imageView, null);
    }
    LinearLayout rlayout = (LinearLayout) getView().findViewById(R.id.expanded_image_relative);
    rlayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStack();
        }
    });
    Button saveButton = (Button) getView().findViewById(R.id.save_image_button);
    saveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ContentValues values = new ContentValues();
            values.put(Images.Media.TITLE, id);
            values.put(Images.Media.DESCRIPTION, id);
            values.put(Images.Media.MIME_TYPE, "image/jpeg");
            values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());

            Uri uri = null;
            ContentResolver contentResolver = getActivity().getContentResolver();
            try {
                uri = contentResolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
                OutputStream imageOut = contentResolver.openOutputStream(uri);
                try {
                    image.compress(Bitmap.CompressFormat.JPEG, 90, imageOut);
                } finally {
                    imageOut.close();
                }
                Toast.makeText(getActivity(), "Saved to gallery.", Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                Toaster.toastShort("Failed to save to gallery.");
                if (uri != null) {
                    contentResolver.delete(uri, null, null);
                    uri = null;
                }
            }
        }
    });
}

From source file:com.example.meetingapp.ShowDetailsFragment.java

/**
 * Adds an image to the HorizontalScrollView.
 * @param image Image to be added to the HorizontalScrollView.
 *///www.j av a  2s  .com
private void addImage(Bitmap image) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setGravity(Gravity.CENTER);

    /* Set parameters - we want a small divider of 3 pixels so we can
     * easily distinguish different photos.
     */
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(3, 0, 0, 0);
    params.gravity = Gravity.CENTER;

    ImageView imageView = new ImageView(getActivity());
    imageView.setScaleType(ScaleType.CENTER);
    imageView.setImageBitmap(image);
    imageView.setLayoutParams(params);

    layout.addView(imageView);
    mPhotosView.addView(layout);
}

From source file:com.microsoft.projectoxford.visionsample.RecognizeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("AnalyzeActivity", "onActivityResult");
    switch (requestCode) {
    case REQUEST_SELECT_IMAGE:
        if (resultCode == RESULT_OK) {
            // If image is selected successfully, set the image URI and bitmap.
            mImageUri = data.getData();//from  ww w .ja  v  a2  s. c om

            mBitmap = ImageHelper.loadSizeLimitedBitmapFromUri(mImageUri, getContentResolver());
            if (mBitmap != null) {
                // Show the image on screen.
                ImageView imageView = (ImageView) findViewById(R.id.selectedImage);
                imageView.setImageBitmap(mBitmap);

                // Add detection log.
                Log.d("AnalyzeActivity", "Image: " + mImageUri + " resized to " + mBitmap.getWidth() + "x"
                        + mBitmap.getHeight());

                doRecognize();
            }
        }
        break;
    default:
        break;
    }
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

public BGAViewHolderHelper setImageBitmap(@IdRes int viewId, Bitmap bitmap) {
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}

From source file:com.aizen.manga.util.ImageWorker.java

/**
 * Load a local image into an ImageView (override
 * {@link ImageWorker#processBitmap(Object)} to define the processing logic). 
 * /*from   w ww  .j  a v a 2  s  .c o m*/
 * @param imageURI The URI of the local image to load.
 * @param imageView The ImageView to bind the image to.
 */
public void loadLocalImage(String imageURI, ImageView imageView) {
    imageView.setImageBitmap(BitmapFactory.decodeFile(imageURI));
}

From source file:gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Window and view properties
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.camera_preview);

    // Load bitmap from intent data and display in imageview
    mImageUri = getIntent().getData();// w w w . j ava2  s .c o  m
    try {
        mImageData = new JSONObject(getIntent().getExtras().getString("data"));
    } catch (JSONException e1) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error unserializing JSON data from intent");
        mImageData = new JSONObject();
    }

    try {
        final BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 4;
        InputStream in = getContentResolver().openInputStream(mImageUri);
        Bitmap bitmap = BitmapFactory.decodeStream(in, null, opts);

        //Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri);
        ImageView imageView = (ImageView) findViewById(R.id.camera_preview_imageview);
        imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ScaleType.CENTER_INSIDE);
        imageView.setImageBitmap(bitmap);
    } catch (FileNotFoundException e) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error loading bitmap in CameraPreviewActivity");
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String defaultNotes = settings.getString(GeoCamMobile.SETTINGS_DEFAULT_NOTES_KEY, "");

    // Set default notes
    EditText notesText = (EditText) findViewById(R.id.camera_preview_edittext);
    notesText.setText(defaultNotes + " ");

    // Buttons
    mFireButton = (ImageButton) findViewById(R.id.camera_preview_fire_button);
    mFireButton.setImageDrawable(getResources().getDrawable(R.drawable.fire_icon_default));
    mFireButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_PICK);
            intent.setClass(CameraPreviewActivity.this, FireIconActivity.class);
            startActivityForResult(intent, PICK_ICON_REQUEST);
        }
    });

    final ImageButton deleteButton = (ImageButton) findViewById(R.id.camera_preview_delete_button);
    deleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            CameraPreviewActivity.this.showDialog(DIALOG_DELETE_PHOTO);
        }
    });

    final ImageButton saveButton = (ImageButton) findViewById(R.id.camera_preview_save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mImageNote = ((EditText) findViewById(R.id.camera_preview_edittext)).getText().toString();
            Log.d(GeoCamMobile.DEBUG_ID, "Setting image note to: " + mImageNote);
            saveWithAnnotation();
        }
    });

    mForeground = new ForegroundTracker(this);
}

From source file:com.carver.paul.truesight.Ui.MainActivity.java

private void setTopImage(Bitmap photoBitmap) {
    ImageView topImage = (ImageView) findViewById(R.id.image_top);
    topImage.setVisibility(View.VISIBLE);
    topImage.setImageBitmap(photoBitmap);
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

public BaseViewHolderHelper setImageBitmap(@IdRes int viewId, Bitmap bitmap) {
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}

From source file:fm.smart.r1.activity.ItemActivity.java

static void setSound(ImageView sound_icon, final String sound_url, final Context context, final int type_id,
        final String artifact_id, final String to_record) {
    if (!TextUtils.isEmpty(sound_url)) {
        OnClickListener sound_listener = new OnClickListener() {
            public void onClick(View v) {
                Main.playSound(sound_url, ItemListActivity.mMediaPlayer, context);
            }//from   w w  w.j  av a2  s. c om
        };
        sound_icon.setOnClickListener(sound_listener);
    } else {
        if (type_id == R.id.response_sound || type_id == R.id.translation_sound) {
            sound_icon.setVisibility(View.INVISIBLE);
        } else {
            sound_icon.setImageBitmap(
                    BitmapFactory.decodeResource(context.getResources(), R.drawable.inactive_sound_add));

            OnClickListener listener = new OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setClassName(context, CreateSoundActivity.class.getName());
                    Utils.putExtra(intent, "item_id", (String) item.item_node.atts.get("id"));
                    Utils.putExtra(intent, "to_record", to_record);
                    Utils.putExtra(intent, "id", artifact_id);
                    Utils.putExtra(intent, "sound_type", Integer.toString(type_id));
                    context.startActivity(intent);

                }
            };
            sound_icon.setOnClickListener(listener);
        }
    }
}