嗚嗚喔學習筆記

搜尋此網誌

2015年6月23日 星期二

ASP.net MVC5 - [ LINQ ]


LINQ - 常用四種方法 where , any , all , select


程式碼:
var number = new int[] { 10, 200, 300, 400, 500 };

//查詢 number[i] > 300 的數值
var where = number.Where(p => p > 300);
foreach( var item in where)
{
    System.Diagnostics.Debug.WriteLine("where item = " + item);
}

//是否有 number[i] == 200 的數值
var any = number.Any(p => p == 200);
System.Diagnostics.Debug.WriteLine("any number[i] == 200 : " + any);

//是否全部都是 number[i] == 300
var all = number.All(p => p == 300);
System.Diagnostics.Debug.WriteLine("all number[i] == 300 : " + all);

//提取資料 並且和成新資料
var select = number.Select(p => "tim"+p).ToArray();
foreach (var item in select)
{
    System.Diagnostics.Debug.WriteLine("select item = " + item);
}

輸出結果 : 

where item = 400
where item = 500
any number[i] == 200 : True
all number[i] == 300 : False
select item = tim10
select item = tim200
select item = tim300
select item = tim400

select item = tim500

2015年6月16日 星期二

Android[ ArrayList ]




程式碼:

        int a =1;
        int b =2;
        int c =3;
        ArrayList<Integer> list = new ArrayList();
        list.add(a);
        list.add(b);
        list.add(c);

        for(int i = 0 ; i < list.size(); i++ )
            Log.d("ooxx","first LinkedList"+list.get(i));

        for(int i = 0 ; i < list.size(); i++ )
        {
            if (list.get(i) == 2 ) {
                list.remove(i);
                list.add(2);
            }
        }

        for(int i = 0 ; i < list.size(); i++ )

            Log.d("ooxx","second LinkedList"+list.get(i));

結果:


2015年4月23日 星期四

Android[ how to get RGB values of bitmap in android ]

讀取Bitmap Pixel ARGB (Alpha,red,green,blue),
並且轉換為灰階 (灰階公式: gray = (r*0.299 + g*0.587 + b*0.114))

相較於 bitmap 的 getPixels() 函式快了許多!! 

程式碼:

public static Bitmap toGray(Bitmap src){
        int bmWidth  = src.getWidth();
        int bmHeight = src.getHeight();
        int[] newBitmap = new int[bmWidth * bmHeight];

        src.getPixels(newBitmap, 0, bmWidth, 0, 0, bmWidth, bmHeight);

        for (int h = 0; h < bmHeight; h++){
            for (int w = 0; w < bmWidth; w++){
                int index = h * bmWidth + w;
                int a = (newBitmap[index] >> 24) & 0xff;//讀取Alpha
                int r = (newBitmap[index] >> 16) & 0xff;//讀取red
                int g = (newBitmap[index] >> 8) & 0xff;//讀取green
                int b =  newBitmap[index] & 0xff;//讀取blue
                int gray = (int)(r*0.299 + g*0.587 + b*0.114) ;

                r = gray;
                g = gray;
                b = gray;

                newBitmap[index] = (a << 24) | (r << 16) | (g << 8) | b;
            }
        }

        Bitmap mBmp = Bitmap.createBitmap(bmWidth, bmHeight, Bitmap.Config.ARGB_8888);
        mBmp.setPixels(newBitmap, 0, bmWidth, 0, 0, bmWidth, bmHeight);

        return mBmp;
    }

2015年3月24日 星期二

OPENCV[ taking address of temporary [-fpermissive] ]

最近做android NDK 開發opencv 遇到的問題

Mat ->  IplImage

本來在 VC++ 2012 的寫法:



Mat Mimg = imread("lena.jpg", 1);//用Mat型別讀取圖片
IplImage* img ;//先宣告 IplImage* 型別的img
img = &IplImage(Mimg);//Matimg的位置丟給img

error:
taking address of temporary [-fpermissive]

解決方法:

Mat Mimg = imread("lena.jpg", 1);//用Mat型別讀取圖片
IplImage imgtemp = Mimg ;//先宣告 IplImage* 型別的img
IplImage *img = &imgtemp ; 

2015年2月2日 星期一

Corona SDK - [ lua 分割中英參雜的字串( UTF-8 ) ]

Lua -- 分割中英參雜的字串( UTF-8 )


程式碼:



































結果: 把 "我是誰123 ABC abc" 分割了~~






















參考資料: http://anyexxx.diandian.com/post/2013-07-30/40053147587

2014年12月9日 星期二

Corona SDK - [config.lua 的萬用設定]

config.lua 的萬用設定 : 
不論是 Iphone 4, Iphone 4s,Iphone 5 ,Iphone6 ,Iphone6 plus , Ipad....
或是 Android 各種各式各樣的大小 都可以一次搞定 !!!

scale直接設定 letterbox 也能適應每種手機的大小 !!!


PS : 利用實機的"長寬",求出比例: (display.pixelHeight / display.pixelWidth)

程式碼 : 

application =
   {
      content =
      {
         width = 320,
         height = 320*(display.pixelHeight / display.pixelWidth), 
         scale = "letterbox",
         xAlign = "center",
         yAlign = "center",
         imageSuffix =
         {
            ["@2x"] = 1.5,
            ["@4x"] = 3.0,
         },
      },
   }  

2014年10月13日 星期一

Corona SDK - [ android keystore lost alias ]

有了 keystore 卻忘了 alias 怎麼辦呢?

輸入以下指令 :
 keytool -list  -v -keystore X:/XXXX /XXXX.keystore -storepass XXXX

 X:/XXXX /XXXX.keystore 輸入絕對keystore的絕對位置 和名稱 
 -storepass XXXX  的 XXXX 輸入keystore的密碼 

結果: 
這時候找到了 別名名稱就是你的 alias

參考資料 : http://blog.csdn.net/tony1130/article/details/5134318