Android一些知识点

阅读更多
1、缓存用户的设置,记住用户的选择
 
	/**
	  * 方法:将用户的相册皮肤SD卡里存在的路径存入Preferences
	  */
   public void saveSkinPath(String path){
   	SharedPreferences ssp = getPreferences(MODE_WORLD_WRITEABLE);
	//获得Preferences
   	SharedPreferences.Editor editor = ssp.edit();			//获得Editor
   	editor.putString("skinPath", path);							//将改动后的皮肤存入Preferences
   	changePath = path;
   	System.out.println("saveSkinPath()---> " + changePath);
   	editor.commit();
   }
 
 
    /**
    * 方法:从Preferences中读取用户设置的相册皮肤路径
    * 只针对此Activity设置背景图片
    */
   public String getSkinPath(){
	   SharedPreferences ssp = getPreferences(MODE_WORLD_WRITEABLE);	//获得Preferences
	   String path = ssp.getString("skinPath", null);
	   if(path != null){
		  changePath = path;
		  return path;
	   }
	   return QuickAccessActivity.getPath();
   }

2、调用系统照相机设置
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
this.startActivityForResult(intent, 111111);

if(resultCode == 111111){
if(data!=null) { 					             Intent takePictureIntent = new Intent(this,PhotoHandle.class);
Bitmap bmp = (Bitmap)(data.getExtras().get("data")); 
byte[] dataBytes = BitmapUtils.getBytes(bmp); 
takePictureIntent.putExtra("data", dataBytes);	//将图片数据设置为Extra
startActivity(takePictureIntent);		//启动保存图片Activity
					}

3、将字节数组转化为图片格式并保存指定路径下
Bitmap bmp = BitmapFactory.decodeByteArray(photoData,0,photoData.length);
File f = new File(Config_constant.CAPTURE_PATH + "/" + albumsList.get(position) + "//" + photoName + ".jpg");
try {
	BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
	bmp.compress(Bitmap.CompressFormat.JPEG, 80, bos);
	bos.flush();
} catch (FileNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}


4、简单的行式布局ListView的用法




        

下面的是具体的代码
ArrayAdapter listAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,listName); // listName是一个字符串数组
this.setListAdapter(listAdapter);

5、将图片转换为字节数组
        /**
	 * 将图片转换为字节数组
	 * @param bmp	图片
	 * @return	字节数组
	 */
	public static byte[] getBytes(Bitmap bmp){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);  
		byte[] dataBytes = baos.toByteArray(); 
		return dataBytes;
	}

你可能感兴趣的:(照相,ListView,图片)