package com.example.uniwall;

import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

//¨M©w§â±±¨îbitmap¹Bºâ²¾¥X¥~­±¡AbimapOperation.java
//­pºâ¤j¤p¡BŪ¨ú¹ÏÀÉ
//MainActivity.java«h¬O­n¨Ì·ÓŪ¥Xªº¹ÏÀÉ¡A³]©w­I´º¹Ï¡C
//¤£½T©wbimapOperation.javaªº¹Bºâ·|¤£·|¦û¥Î¤º¦s¦Ó¤£®ø¥¢¡A³y¦¨¥t¤@­Óout of memory

public class BitmapOperation{
	//Declare variable
	private static int picWidth;
	private static int picHeight;
	//Method for reading file
	public static  Bitmap  readBitMap(Context context, int resId){
		BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;
        // Àò¨ú¸ê·½¹Ï¤ù
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
	}
	
	//Scale the bitmap
	public BitmapFactory.Options getBitmapOptions(int scale){
	    BitmapFactory.Options options = new BitmapFactory.Options();
	    options.inPurgeable = true;
	    options.inInputShareable = true;
	    options.inSampleSize = scale;
	    return options;
	}
	
	//Method for show the information of bitmap without loading picture. 
	public static void informBitmap(String pathName){
		BitmapFactory.Options opts = new BitmapFactory.Options();    
	    // ³]¸minJustDecodeBounds¬°true    
	    opts.inJustDecodeBounds = true;    
	    // ¨Ï¥ÎdecodeFile¤èªk±o¨ì¹Ï¤ùªº¼e©M°ª 
	    BitmapFactory.decodeFile(pathName, opts);    
	    // ¦C¦L¥X¹Ï¤ùªº¼e©M°ª
	    Log.d("example", opts.outWidth + "," + opts.outHeight);
	    
		picWidth  = opts.outWidth;  
		picHeight = opts.outHeight; 
	}
	
	//Get method & set method
//	public int getWidth(){
//		return opts.outWidth;
//	}
//	public int getHeight(){
//		return opts.outHeight;
//	}
}
