adamrockerです。
確かにできましたー。
public class AssetTestActivity extends Activity implements OnClickListener {
private Button mBtn;
private ImageView mImg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBtn = (Button) findViewById(R.id.copy_and_view_btn);
mBtn.setOnClickListener(this);
mImg = (ImageView) findViewById(R.id.result_img);
}
public void onClick(View v) {
if (v == mBtn) {
try {
copyAndView();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private final void copyAndView() throws IOException {
AssetManager as = getResources().getAssets();
InputStream is = as.open("android_img.png"); // アセットファイルのストリーム作成
String toFile = "android_image.png";
copy2Apk(is, toFile); // appローカルにコピー
Bitmap bit = BitmapFactory.decodeFile("/data/data/"
+ this.getPackageName() + "/files/" + toFile);
mImg.setImageBitmap(bit);
is.close();
as.close();
}
private void copy2Apk(InputStream input, String file)
throws IOException {
FileOutputStream output = openFileOutput(file,
Context.MODE_WORLD_READABLE);
int DEFAULT_BUFFER_SIZE = 1024 * 4;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
output.close();
}
}
2009/08/14 0:00 に Katsuhiko Sato<
stk...@ubilabo.net> さんは書きました: