2010年12月30日 星期四

Android 縮小讀圖方法(OutOfMemoryError解法)

在使用bitmap處裡影像轉換時,是不是常常出現
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
的錯誤呢

網路上普遍的說法是bitmap.recycle()
但其實是因為你讀取的原圖大過限制的關係,處裡方法如下


BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;

縮小成1/4,在放進bitmap中

Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);
Bitmap originalImage = BitmapFactory.decodeResource(getResources(), imageId, options);


希望對你有幫助:D

2010年12月1日 星期三

華強北!山寨電子產品聚落!大開眼界

今天花了點時間在網路上看大陸山寨品
真是驚人阿,中國成為世界強國指日可待阿XDD
就讓我來為您介紹幾款我覺得有趣的



iPod Shuffle2
蘋果最新產品引領風潮.


2010年11月29日 星期一

G1 USB HOST

改造G1使其擁有USB HOST
1. 取得手機root權限
2. 刷rom,取得新版fastboot1.3
(在此,我是使用國外論壇釋出的「CyanodenMod-6.0.0-DS」,Ver:2.2,build number:FRF91)
3. 刷經修改過的zImage(root@ubuntu)
4. 安裝手機終端機
5. 掛載usb驅動模組 insmod usbcore.ko , insmod ehci-hcd.ko
6. 掛載輸入驅動模組 insmod usbhid.ko

插上外接電源的usb hub的鍵盤

2010年11月2日 星期二

Android drawable 轉 bitmap

Bitmap drawableToBitmap(Drawable drawable) {
 Bitmap.Config mConfig;
 if(drawable.getOpacity() != PixelFormat.OPAQUE){
  mConfig=Bitmap.Config.ARGB_8888;
 }else{
  mConfig=Bitmap.Config.RGB_565; 
 }
 Bitmap bitmap = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),  mConfig);
 Canvas canvas = new Canvas(bitmap);
 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
 drawable.draw(canvas);
 return bitmap;
}


或者你也可以這樣:)

((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();

Android bitmap轉drawable

要怎麼把bitmap轉成drawable呢?


Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a01);
Drawable mDrawable = new BitmapDrawable(mBitmap);

2010年10月29日 星期五

怎麼在blogger貼程式碼

首先 ,到 SyntaxHighLighter下載檔案
http://alexgorbatchev.com/SyntaxHighlighter/
並找一個空間host裡面的js,css檔案

假設我們存放在xxx.xxx.xxx裡面

登入blogger,並至設定,修改html裡面


<!-- 設定載入 shCore.css 與 shThemeDefault.css --> 
<link href='http://xxx.xxx.xxx/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://xxx.xxx.xxx/shThemeDefault.css' rel='stylesheet' type='text/css'/> 
<!-- 設定需要載入的核心檔案 shCore.js --> 
<script src='http://xxx.xxx.xxx/shCore.js' type='text/javascript'/> 
<!-- 設定需要載入的程式語言檔案 --> 
<script src='http://xxx.xxx.xxx/shBrushJScript.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushSql.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushVb.js' type='text/javascript'/> 
<script src='http://xxx.xxx.xxx/shBrushXml.js' type='text/javascript'/> 
<!-- 設定啟用 highlighter --> 
<script type='text/javascript'> 
     SyntaxHighlighter.config.bloggerMode = true; 
     SyntaxHighlighter.all()
</script> 


將前述程式碼貼在 <body> 後面
儲存,就算是設定完成了



平時貼程式碼的方法,假設我要貼下列程式碼

function helloSyntaxHighlighter()
{
 return "hi!";
}

就在發表文章中的修改html以下列方式撰寫

<pre class="brush: js;">
function helloSyntaxHighlighter()
{
return "hi!";
}
</pre>

如果你的文字有特殊字元,不要忘記先encode,
http://www.opinionatedgeek.com/dotnet/tools/htmlencode/encode.aspx

Android要怎麼做出透明Activity

首先在
在res/values/中加入一個新的檔案

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>
</resources>


在res/values/中加入一個新的檔案

color.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>
</resources>



最後在AndroidManifest中,Activity設定修改Theme 為 @style/Theme.Transparent