androidfilebitmap
A. android 如何将drawable中的图片保存到系统相册中
android 将drawable中的图片保存到系统相册中的原理比较简单,获取到的bitmap,然后通过的compress方法写到一个fileoutputstream中. 再通知MediaScannerService有图片文件加入就可以了.
保存图片的核心代码如下:
Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, name, "");
或者
FileOutputStream fos = openFileOutput("image", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
//发送系统通知消息
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
另一种方法是直接使用文件流读写:
InputStream is = mContext.getResources().openRawResource(PicID);
FileOutputStream fos = new FileOutputStream(LogoFilePath);
byte[] buffer = new byte[8192];
int count = 0;
while((count=is.read(buffer)) > 0)
{
fos.write(buffer, 0, count);
}
fos.close();
is.close();
这里要注意目录权限问题:在应用程序AndroidManifest.xml中的manifest节点中加入android:sharedUerId="android.uid.system"这个属性。然后放在源码环境中编译,并通过adb install 的方式进行安装。mk文件中的属性改为LOCAL_CERTIFICATE :=platform。
B. 如何读写Android的WebView缓存文件
简单步骤解答:
新建一个Android工程命名为WebViewCache。
在assets目录下新建一个html文件,命名为index.html。
修改主核心程序WebViewCacheDemo.java,这里我只加载了index.html文件。
在AndroidMainifest.xml文件中加访问网络的权限。
请求的url记录是保存在webviewCache.db,而url的内容是保存在webviewCache文件夹下。
C. 请问在android 编程,Bitmap 怎么转换成 file
static boolean saveBitmap2file(Bitmap bmp,String filename){
CompressFormat format= Bitmap.CompressFormat.JPEG;
int quality = 100;
OutputStream stream = null;
try {
stream = new FileOutputStream("/sdcard/" + filename);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmp.compress(format, quality, stream);
}
stream = new FileOutputStream("/sdcard/" + filename);
获取要保存到的文件的文件流
bmp.compress(format, quality, stream);
把指定的bitmp压缩到文件中 就是保存在指定文件中 format是文件格式(Bitmap.CompressFormat.JPEG jpeg) quality 是品质(100 就是原质量)
看名字 saveBitmap2file
你要上传的话 就去指定位置取这个file就行 路径的问题 可能有写真机找不到/sdcard/
建议 Environment类取地址 保存和读取时 都用Environment.getXXXX
D. android开发怎么将webp格式转换为jpg格式
把PNG格式的文件解析成BYTE数组然后再组合成JPG byte[] b=null; File PNG = null; BufferedOutputStream stream = null; try { PNG = new File(outputFile); FileOutputStream fstream = new FileOutputStream(PNG); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { // log.error("helper:get file from byte process error!"); e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { // log.error("helper:get file from byte process error!"); e.printStackTrace(); } } } Bitmap bitmap=BitmapFactory.decodeByteArray(b, 0, b.length); 擦..发现自己弄的是BMP格式..反正就这样差不多了..
E. Cocos Creator怎么使用安卓手机相册中的图片,最好有示例源码
android 将drawable中的图片保存到系统相册中的原理比较简单,获取到的bitmap,然后通过的compress方法写到一个fileoutputstream中. 再通知MediaScannerService有图片文件加入就可以了.
保存图片的核心代码如下:
Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, name, "");
或者
FileOutputStream fos = openFileOutput("image", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
//发送系统通知消息
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
另一种方法是直接使用文件流读写:
InputStream is = mContext.getResources().openRawResource(PicID);
FileOutputStream fos = new FileOutputStream(LogoFilePath);
byte[] buffer = new byte[8192];
int count = 0;
while((count=is.read(buffer)) > 0)
{
fos.write(buffer, 0, count);
}
fos.close();
is.close();
这里要注意目录权限问题:在应用程序AndroidManifest.xml中的manifest节点中加入android:sharedUerId="android.uid.system"这个属性。然后放在源码环境中编译,并通过adb install 的方式进行安装。mk文件中的属性改为LOCAL_CERTIFICATE :=platform。