搜尋此網誌
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;
}
並且轉換為灰階 (灰階公式: 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 遇到的問題
本來在 VC++ 2012 的寫法:
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
程式碼:
結果: 把 "我是誰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,
},
},
}
不論是 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的密碼
結果:
輸入以下指令 :
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
2014年10月12日 星期日
訂閱:
文章 (Atom)


