日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android复制图片,android图像保存到res / drawable文件夹[复制]

發布時間:2023/12/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android复制图片,android图像保存到res / drawable文件夹[复制] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參見英文答案 >

Write to /res/drawable/ on the fly?3個

我想將圖像保存到我的本地驅動器文件夾或我的應用程序中的res / drawable文件夾.我現在正在將img保存到SD卡中,但我要將它保存在res / drawable文件夾中.

我的代碼是:

String image_URL = "http://chart.apis.google.com/chart?chs=200x200&cht=qr&chl=http%3A%2F%2Fandroid-er.blogspot.com%2F";

String extStorageDirectory;

Bitmap bm;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button buttonSave = (Button) findViewById(R.id.save);

ImageView bmImage = (ImageView) findViewById(R.id.image);

BitmapFactory.Options bmOptions;

bmOptions = new BitmapFactory.Options();

bmOptions.inSampleSize = 1;

bm = LoadImage(image_URL,bmOptions);

bmImage.setImageBitmap(bm);

extStorageDirectory = Environment.getExternalStorageState().toString();

extStorageDirectory = Environment.getExternalStorageDirectory()

.toString();

buttonSave.setText("Save to " + extStorageDirectory + "/qr.PNG");

buttonSave.setOnClickListener(buttonSaveOnClickListener);

}

private Bitmap LoadImage(String URL,BitmapFactory.Options options) {

Bitmap bitmap = null;

InputStream in = null;

try {

in = OpenHttpConnection(URL);

bitmap = BitmapFactory.decodeStream(in,null,options);

in.close();

} catch (IOException e1) {

}

return bitmap;

}

private InputStream OpenHttpConnection(String strURL) throws IOException {

InputStream inputStream = null;

URL url = new URL(strURL);

URLConnection conn = url.openConnection();

try {

HttpURLConnection httpConn = (HttpURLConnection) conn;

httpConn.setRequestMethod("GET");

httpConn.connect();

if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {

inputStream = httpConn.getInputStream();

}

} catch (Exception ex) {

}

return inputStream;

}

Button.OnClickListener buttonSaveOnClickListener = new Button.OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

OutputStream outStream = null;

File file = new File(extStorageDirectory,"er.PNG");

try {

outStream = new FileOutputStream(file);

bm.compress(Bitmap.CompressFormat.PNG,100,outStream);

outStream.flush();

outStream.close();

Toast.makeText(LoadSaveImgActivity.this,"Saved",Toast.LENGTH_LONG).show();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Toast.makeText(LoadSaveImgActivity.this,e.toString(),Toast.LENGTH_LONG).show();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

Toast.makeText(LoadSaveImgActivity.this,Toast.LENGTH_LONG).show();

}

}

};

總結

以上是生活随笔為你收集整理的android复制图片,android图像保存到res / drawable文件夹[复制]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。