同一个线程即不需要启动thread,直接调用saveImage
异步线程的话启动thread,用queueEvent把saveImage丢进队列执行
在进行Android开发过程中,我们经常会接触到Drawable对象(官方开发文档:A Drawable is a general abstraction for "something that can be drawn."),那么,若要使用数据库来进行存储及读取.@Override
public void onCreate(SQLiteDatabase database) {
executeSQLScript(database, "create.sql")
}
private void executeSQLScript(SQLiteDatabase database, string dbname){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
byte buf[] = new byte[1024]
int len
AssetManager assetManager = context.getAssets()
InputStream inputStream = null
try{
inputStream = assetManager.open(dbname)
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len)
}
outputStream.close()
inputStream.close()
String[] createScript = outputStream.toString().split("")
for (int i = 0i <createScript.lengthi++) {
String sqlStatement = createScript[i].trim()
// TODO You may want to parse out comments here
if (sqlStatement.length() >0) {
database.execSQL(sqlStatement + "")
}
}
} catch (IOException e){
// TODO Handle Script Failed to Load
} catch (SQLException e) {
// TODO Handle Script Failed to Execute
}
}
import java.io.Fileimport android.app.Activity
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import android.widget.ImageView
public class MainAct extends Activity {
private ImageView img
//图片路径
private String filepath = "/sdcard/sample.jpg"
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
img = (ImageView) findViewById(R.id.img)
File file = new File(filepath)
if (file.exists()) {
Bitmap bm = BitmapFactory.decodeFile(filepath)
//将图片显示到ImageView中
img.setImageBitmap(bm)
}
}
}
请参考
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)