【问题标题】:Image of imageview not remove?imageview的图像不删除?
【发布时间】:2012-05-19 03:30:23
【问题描述】:

从 xml.as 获取 id 后我有一个 ImageView 在 ImageView 上,我们设置了打开画廊和相机选项的 clicklistener,您可以设置来自相机的图像以及画廊 #2

   profileimage = (ImageView) findViewById(R.id.profileimage);
    profileimage.setBackgroundResource(R.drawable.no_img);

  protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (resultCode == RESULT_CANCELED) {
        // TODO
        return;
    }
    Log.e("request code", "1:" + requestCode);
    switch (requestCode) {
    case CAMERA_SELECT:
        Log.e("in camera select", "1");
        // Get the camera data
        cameracalling(intent);

        break;
    case Gallery_Select:
        ongallerycalling(intent,resultCode);

    }
}

private void cameracalling(Intent intent){

     Bitmap photo = (Bitmap) intent.getExtras().get("data"); 
     profileimage.setImageBitmap(photo);
 }


profileimage.buildDrawingCache();

Bitmap bmap = profileimage.getDrawingCache();

ByteArrayOutputStream bao = new ByteArrayOutputStream();

bmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);

byte [] ba = bao.toByteArray();

bitmapString=Base64.encodeBytes(ba);


Drawable draw = LoadImageFromWebOperations("" + objUserInformationSitesList.getProfileImage());

profileimage.setBackgroundDrawable(draw);   

我们正在将位图字符串正确发送到服务器上的图像上传,但是当我们下次打开这个屏幕时,我们上传图像的 web 服务调用将提供所有数据(实际上是这个用户配置文件屏幕)。当我们设置服务器图像时默认图像也设置在背景上

objUserInformationSitesList这个对象包含了解析web服务后的所有信息。在个人资料图片后面,默认图片也是我在 #1 上设置的图片

如果我无法正确解释,请告诉我。

【问题讨论】:

    标签: android


    【解决方案1】:

    在 onclicklistener 中使用 profileimage.setBackgroundResource(0);

    【讨论】:

      【解决方案2】:

      你应该替换下面的行:

      profileimage.setBackgroundResource(R.drawable.no_img);
      

      用这一行:

      profileimage.setImageResource(R.drawable.no_img);
      

      您将图像设置为可绘制的背景,然后将位图设置为图像源。所以 imageview 背景不会改变。您应该将图像设置为图像资源。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-29
        • 1970-01-01
        • 2011-10-02
        • 2013-08-06
        • 1970-01-01
        • 2021-05-16
        • 2016-08-08
        • 1970-01-01
        相关资源
        最近更新 更多