首页 > 代码库 > ImageView和Bitmap的转换,实例:设置当前查看图片为桌面背景

ImageView和Bitmap的转换,实例:设置当前查看图片为桌面背景

ImageView转Bitmap

Bitmap bitmap = ((BitmapDrawable)img.getDrawable()).getBitmap();

Bitmap bitmap = ((BitmapDrawable)img.getDrawable()).getBitmap();


	@Override
		public boolean onLongClick(View v) {
			if(v.getId()==R.id.listener_imageView1){
				//长摁设置桌面背景
				//1.清楚已有做面
				try {
					ListenerDemoActivity.this.clearWallpaper();
//					ListenerDemoActivity.this.setWallpaper(getApplicationContext().getResources().openRawResource(R.drawable.pic1));
					textView2.setText("设置手机桌面背景成功!");
					
					Bitmap bitmap = ((BitmapDrawable)img.getDrawable()).getBitmap();
					ListenerDemoActivity.this.setWallpaper(bitmap);
					
				} catch (IOException e) {
					textView2.setText("设置手机桌面背景失败!!");
					e.printStackTrace();
				}
			}
			return false;
		}
	}


ImageView和Bitmap的转换,实例:设置当前查看图片为桌面背景