Skip to content

Instantly share code, notes, and snippets.

@lovelycateyes
lovelycateyes / gist:1985583
Created March 6, 2012 10:28
Android load local image to webview
File file = getFileStreamPath(fileName);
String path = file.getAbsolutePath();
String html = "<body style=\"margin:0;padding:0;border:0;\"><img width=\"100%\" src=\"file://" + path + "\" /></body>";
getWebView().loadDataWithBaseURL("http://noneed.url", html, "text/html", "UTF-8", "about:blank");
@lovelycateyes
lovelycateyes / Demo.java
Created March 6, 2012 10:17
Android load local image to webview
InputStream is;
try {
is = openFileInput(fileName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[10240];
int count;
while(-1 != (count = is.read(buffer, 0, buffer.length))) {
baos.write(buffer, 0, count);
}
@lovelycateyes
lovelycateyes / BitmapHelper.java
Created December 23, 2011 04:56
Reflection Effect
public class BitmapHelper {
//gapRatio:間距的比例
//reflectRatio:鏡像的比例
public static Bitmap reflection(Bitmap src, float gapRatio, float reflectRatio) {
int origWidth = src.getWidth();
int origHeight = src.getHeight();
int gapHeight = Float.valueOf(origHeight * gapRatio).intValue();
int reflectHeight = Float.valueOf(origHeight * reflectRatio).intValue();
//統一色彩定義,讓圖片色盤不會跑掉。不然jpg沒有alpha channel會很怪。