android.widget.ImageView.setImageBitmap()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(359)

本文整理了Java中android.widget.ImageView.setImageBitmap()方法的一些代码示例,展示了ImageView.setImageBitmap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageView.setImageBitmap()方法的具体详情如下:
包路径:android.widget.ImageView
类名称:ImageView
方法名:setImageBitmap

ImageView.setImageBitmap介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
  Bitmap mIcon1 =
    BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
  profile.setImageBitmap(mIcon1);
}

代码示例来源:origin: stackoverflow.com

File imgFile = new  File("/sdcard/Images/test_image.jpg");

if(imgFile.exists()){

  Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

  ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

  myImage.setImageBitmap(myBitmap);

}

代码示例来源:origin: stackoverflow.com

private void loadImageFromStorage(String path)
{

  try {
    File f=new File(path, "profile.jpg");
    Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
      ImageView img=(ImageView)findViewById(R.id.imgPicker);
    img.setImageBitmap(b);
  } 
  catch (FileNotFoundException e) 
  {
    e.printStackTrace();
  }

}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public View onCreateView(LayoutInflater inflater,
             ViewGroup container,
             Bundle savedInstanceState) {
 View result=inflater.inflate(R.layout.sample, container, false);
 int inSampleSize=getArguments().getInt(KEY_SAMPLE_SIZE, 1);
 try {
  Bitmap flower=
    load("Tibouchina_urvilleana_flower_ja.jpg", inSampleSize);
  Bitmap logo=load("square.png", inSampleSize);
  ImageView iv=(ImageView)result.findViewById(R.id.flower_large);
  iv.setImageBitmap(flower);
  iv=(ImageView)result.findViewById(R.id.flower_small);
  iv.setImageBitmap(flower);
  iv=(ImageView)result.findViewById(R.id.logo_large);
  iv.setImageBitmap(logo);
  iv=(ImageView)result.findViewById(R.id.logo_small);
  iv.setImageBitmap(logo);
  TextView tv=(TextView)result.findViewById(R.id.byte_count);
  tv.setText(String.valueOf(byteCount(flower)));
 }
 catch (IOException e) {
  Log.e(getClass().getSimpleName(), "Exception loading bitmap", e);
 }
 return(result);
}

代码示例来源:origin: stackoverflow.com

// Find the last picture
String[] projection = new String[]{
  MediaStore.Images.ImageColumns._ID,
  MediaStore.Images.ImageColumns.DATA,
  MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
  MediaStore.Images.ImageColumns.DATE_TAKEN,
  MediaStore.Images.ImageColumns.MIME_TYPE
  };
final Cursor cursor = getContext().getContentResolver()
    .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, 
        null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");

// Put it in the image view
if (cursor.moveToFirst()) {
  final ImageView imageView = (ImageView) findViewById(R.id.pictureView);
  String imageLocation = cursor.getString(1);
  File imageFile = new File(imageLocation);
  if (imageFile.exists()) {   // TODO: is there a better way to do this?
    Bitmap bm = BitmapFactory.decodeFile(imageLocation);
    imageView.setImageBitmap(bm);         
  }
}

代码示例来源:origin: stackoverflow.com

File(Environment.getExternalStorageDirectory()
.getAbsolutePath()
+ "/images");
 ImageView imageView = new ImageView(this);
 Bitmap imbm = BitmapFactory.decodeFile(parent.listFiles()[count]
     .getAbsolutePath());
 imageView.setImageBitmap(imbm);
 imageView.setLayoutParams(params);
 flipper.addView(imageView);

代码示例来源:origin: stackoverflow.com

+ File.separatorChar
            + System.currentTimeMillis() + ".jpg";
        File file = new File(path);
          if (file.exists() == false) {
            file.getParentFile().mkdirs();
            file.createNewFile();
mImageView = (ImageView) findViewById(R.id.iv_photo);
button.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
        + selectedImagePath);
    File file = new File(Environment.getExternalStorageDirectory(),
        selectedImagePath);
    mImageView.setImageBitmap(bm);

代码示例来源:origin: nanchen2251/AiYaCompressHelper

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK) {
    if (data == null) {
      showError("Failed to open picture!");
      return;
    }
    try {
      oldFile = FileUtil.getTempFile(this, data.getData());
      mImageOld.setImageBitmap(BitmapFactory.decodeFile(oldFile.getAbsolutePath()));
      mTextOld.setText(String.format("Size : %s", getReadableFileSize(oldFile.length())));
      clearImage();
    } catch (IOException e) {
      showError("Failed to read picture data!");
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: pili-engineering/PLDroidShortVideo

private void configVideoItem(ViewHolder holder, PLComposeItem item) {
  Bitmap bitmap = getVideoThumbnail(item.getFilePath());
  if (bitmap != null) {
    holder.mItemThumbnail.setImageBitmap(bitmap);
  }
  PLMediaFile file = new PLMediaFile(item.getFilePath());
  holder.mItemName.setText("文件名:" + new File(item.getFilePath()).getName());
  if (file.hasVideo()) {
    String videoParams = "视频:" + file.getVideoWidth() + "x" + file.getVideoHeight() + ", " + file.getVideoRotation() + " 度";
    holder.mItemParams.setText(videoParams);
  }
  if (file.hasAudio()) {
    String audioParams = "音频:" + file.getAudioSampleRate() + "Hz, ";
    if (file.getAudioChannels() == 1) {
      audioParams += "单通道";
    } else {
      audioParams += "立体声";
    }
    holder.mItemDuration.setText(audioParams);
  } else {
    holder.mItemDuration.setText("音频:无");
  }
  file.release();
}

代码示例来源:origin: stackoverflow.com

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

  View view=inflater.inflate(R.layout.tab1,container,false);
  ImageView iklansatu = (ImageView) view.findViewById(R.id.iklanpertama);

    try {
      URL newurl = new URL(gambar1[0]);
      Bitmap mIcon_val = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
      iklansatu.setImageBitmap(mIcon_val);
      } catch (Exception e) {
    }

  return  view;
}

代码示例来源:origin: stackoverflow.com

String urlString = "http://your image url";
URL url  = new URL(urlString);
ImageView imageView = (ImageView)findViewById(R.id.userImage);
if (imageView != null) {
  Bitmap bmIcon = BitmapFactory.decodeStream(url_url.openConnection().getInputStream());
  imageView.setImageBitmap(bmIcon);
}

代码示例来源:origin: novoda/android-demos

public View getView(int position, View convertView, ViewGroup parent) {
    View view;
    if (convertView == null) {
      final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
          Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.carousel_gallery_li, null);
    } else {
      view = convertView;
    }

    final ImageView imageView = (ImageView) view.findViewById(R.id.image);

    Bitmap image = null;
    try {
      InputStream bitmap = mContext.getAssets().open(PLACEHOLDER_FILE);
      image = BitmapFactory.decodeStream(bitmap);
    } catch (IOException exception) {
      Log.e(TAG, "An error occurred when you have tried to open the file: "+ PLACEHOLDER_FILE, exception);
    }

    imageView.setImageBitmap(image);
    return view;
  }
}

代码示例来源:origin: eleme/UETool

@Override
  public void bindView(BitmapItem bitmapItem) {
    super.bindView(bitmapItem);
    vName.setText(bitmapItem.getName());
    Bitmap bitmap = bitmapItem.getBitmap();
    int height = Math.min(bitmap.getHeight(), imageHeight);
    int width = (int) ((float) height / bitmap.getHeight() * bitmap.getWidth());
    ViewGroup.LayoutParams layoutParams = vImage.getLayoutParams();
    layoutParams.width = width;
    layoutParams.height = height;
    vImage.setImageBitmap(bitmap);
    vInfo.setText(bitmap.getWidth() + "px*" + bitmap.getHeight() + "px");
  }
}

代码示例来源:origin: mayubao/KuaiChuan

viewHolder.iv_shortcut.setImageBitmap(fileInfo.getBitmap());
  }else{
    if(FileUtils.isApkFile(fileInfo.getFilePath())){
      viewHolder.iv_shortcut.setImageBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.icon_apk));
    }else if(FileUtils.isMp4File(fileInfo.getFilePath())){
      viewHolder.iv_shortcut.setImageBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.icon_mp4));
    viewHolder.iv_shortcut.setImageBitmap(fileInfo.getBitmap());
  }else{
    viewHolder.iv_shortcut.setImageBitmap(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.icon_jpg));
viewHolder.tv_name.setText(FileUtils.getFileName(fileInfo.getFilePath()));
  long total = fileInfo.getSize();
  viewHolder.pb_file.setVisibility(View.GONE);
  viewHolder.tv_progress.setText(FileUtils.getFileSize(total) + "/" + FileUtils.getFileSize(total));
    viewHolder.btn_operation.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
  long progress = fileInfo.getProcceed();
  long total = fileInfo.getSize();
  viewHolder.tv_progress.setText(FileUtils.getFileSize(progress) + "/" + FileUtils.getFileSize(total));
  viewHolder.btn_operation.setOnClickListener(new View.OnClickListener() {

代码示例来源:origin: stackoverflow.com

// Create the Snackbar
Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG);
// Get the Snackbar's layout view
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
// Hide the text
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);

// Inflate our custom view
View snackView = mInflater.inflate(R.layout.my_snackbar, null);
// Configure the view
ImageView imageView = (ImageView) snackView.findViewById(R.id.image);
imageView.setImageBitmap(image);
TextView textViewTop = (TextView) snackView.findViewById(R.id.text);
textViewTop.setText(text);
textViewTop.setTextColor(Color.WHITE);

// Add the view to the Snackbar's layout
layout.addView(snackView, 0);
// Show the Snackbar
snackbar.show();

代码示例来源:origin: stackoverflow.com

btnSelect.setOnClickListener(new OnClickListener() {
  protected void onPostExecute(Bitmap result) {
    super.onPostExecute(result);
    iv.setImageBitmap(result);
  if (convertView == null) {
    holder = new ViewHolder();
    convertView = mInflater.inflate(R.layout.custom_gallery_item, null);
    holder.imgThumb = (ImageView) convertView.findViewById(R.id.imgThumb);
    holder.chkImage = (CheckBox) convertView.findViewById(R.id.chkImage);

代码示例来源:origin: GitLqr/LQRWeChat

private void showQRCard() {
  if (mQrCardDialog == null) {
    View qrCardView = View.inflate(getActivity(), R.layout.include_qrcode_card, null);
    ImageView ivHeader = (ImageView) qrCardView.findViewById(R.id.ivHeader);
    TextView tvName = (TextView) qrCardView.findViewById(R.id.tvName);
    ImageView ivCard = (ImageView) qrCardView.findViewById(R.id.ivCard);
    TextView tvTip = (TextView) qrCardView.findViewById(R.id.tvTip);
    tvTip.setText(UIUtils.getString(R.string.qr_code_card_tip));
    UserInfo userInfo = mPresenter.getUserInfo();
    if (userInfo != null) {
      Glide.with(getActivity()).load(userInfo.getPortraitUri()).centerCrop().into(ivHeader);
      tvName.setText(userInfo.getName());
      Observable.just(QRCodeEncoder.syncEncodeQRCode(AppConst.QrCodeCommon.ADD + userInfo.getUserId(), UIUtils.dip2Px(100)))
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe(bitmap -> ivCard.setImageBitmap(bitmap), this::loadQRCardError);
    }
    mQrCardDialog = new CustomDialog(getActivity(), 300, 400, qrCardView, R.style.MyDialog);
  }
  mQrCardDialog.show();
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

@Override
public void onBindViewHolder(int viewType, MyViewHolder viewHolder, BaseDanmaku danmaku, AndroidDisplayer.DisplayerConfig displayerConfig, TextPaint paint) {
  if (paint != null)
    viewHolder.mText.getPaint().set(paint);
  viewHolder.mText.setText(danmaku.text);
  viewHolder.mText.setTextColor(danmaku.textColor);
  viewHolder.mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, danmaku.textSize);
  Bitmap bitmap = null;
  MyImageWare imageWare = (MyImageWare) danmaku.tag;
  if (imageWare != null) {
    bitmap = imageWare.bitmap;
    if (danmaku.text.toString().contains("textview")) {
      Log.e("DFM", "onBindViewHolder======> bitmap:" + (bitmap == null) + "  " + danmaku.tag + "url:" + imageWare.getImageUri());
    }
  }
  if (bitmap != null) {
    viewHolder.mIcon.setImageBitmap(bitmap);
    if (danmaku.text.toString().contains("textview")) {
      Log.e("DFM", "onBindViewHolder======>" + danmaku.tag + "url:" + imageWare.getImageUri());
    }
  } else {
    viewHolder.mIcon.setImageResource(R.drawable.ic_launcher);
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

private void changeAccount(final AccountBean account, final View view) {
  final ImageView imgMove = (ImageView) mHeaderView.findViewById(R.id.imgMove);
  Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  view.draw(canvas);
  imgMove.setImageBitmap(bitmap);
  mHeaderView.findViewById(R.id.material_drawer_account_header_current).getGlobalVisibleRect(targetRect);
  Rect fromRect = new Rect();
  view.getGlobalVisibleRect(fromRect);

代码示例来源:origin: stackoverflow.com

btnAddPhots = (Button)findViewById(R.id.btnAddPhots);
btnSaveImages = (Button)findViewById(R.id.btnSaveImages);
btnAddPhots.setOnClickListener(this);
btnSaveImages.setOnClickListener(this);
      yourbitmap = BitmapFactory.decodeFile(imagesPath[i]);
      ImageView imageView = new ImageView(this);
      imageView.setImageBitmap(yourbitmap);
      imageView.setAdjustViewBounds(true);
      lnrImages.addView(imageView);

相关文章

ImageView类方法