当前位置:首页 » 安卓系统 » androiduribitmap

androiduribitmap

发布时间: 2024-12-28 09:53:46

① Android开发中怎么将照片存储到系统相册中

java">//创建输出流,指向SD卡的Pictures文件夹
finalFiledirectory=Environment.(Environment.DIRECTORY_DCIM);
//创建保存的文件
Filefile=newFile(directory,"test.png");
FileOutputStreamout=null;
try{
out=newFileOutputStream(file);

}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}finally{

}
//bitmap就是你的图片
bitmap.compress(Bitmap.CompressFormat.PNG,100,out);

② Android 视频开发中如何通过url或者本地视

第一步:将bitmap转换成drawable对象,并设置给surfaceView视频播放窗口作为背景图片
//通过getVideoThumbnail方法取得视频中的第一帧图片,该图片是一个bitmap对象Bitmap bitmap=getVideoThumbnail(String url);//将bitmap对象转换成drawable对象Drawable drawable=new BitmapDrawable(bitmap);//将drawable对象设置给视频播放窗口surfaceView控件作为背景图片surfaceView.setBackgroundDrawable(drawable);123456

第二部分:通过url网址或者本地文件路径获得视频的第一帧图片
public Bitmap getVideoThumbnail(String url) {
Bitmap bitmap = null;//MediaMetadataRetriever 是android中定义好的一个类,提供了统一//的接口,用于从输入的媒体文件中取得帧和元数据;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
//()根据文件路径获取缩略图//retriever.setDataSource(filePath);
retriever.setDataSource(url, new HashMap()); //获得第一帧图片
bitmap = retriever.getFrameAtTime();
}
catch(IllegalArgumentException e) {
e.printStackTrace();
}
catch (RuntimeException e) {
e.printStackTrace();
}
finally {
try {
retriever.release();
}
catch (RuntimeException e) {
e.printStackTrace();
}
}
Log.v("bitmap", "bitmap="+bitmap); return bitmap;
}

③ Android 两个Activity之间怎样使用Uri传递图片,怎样获取图片的Uri,怎样通过Uri得到图片

图片类:
class Image implements Serializable{
private String url;
private Bitmap bitmap;
}

传递:
Image image = new Image();
image.seturl(url);
image.setbitmap(bitmap);
intent.putExtra("image", image);

获取
Image image = intent.getSerializableExtra("image");
String url = image.geturl();
Bitmap bitmap =image.getbitmap();

④ android 如何获取保存的图片的地址 并存到数据库

安卓中如何获取保存的图片uri 并保存到sqlite数据库中
有如下两种方法,仅供参考
方法一:Java代码

public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最终图标要保存到浏览器的内部数据库中,系统程序均保存为SQLite格式,Browser也不例外,因为图片是二进制的所以使用字节数组存储数据库的
// BLOB类型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 将Bitmap压缩成PNG编码,质量为100%存储
icon.compress(Bitmap.CompressFormat.PNG, 100, os);
// 构造SQLite的Content对象,这里也可以使用
raw ContentValues values = new ContentValues();
// 写入数据库的
Browser.BookmarkColumns.TOUCH_ICON字段 values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());
DBUtil.update(....);
//调用更新或者插入到数据库的方法
}
}

方法二:如果数据表入口时一个content:URIJava代码

import android.provider.MediaStore.Images.Media;
import android.content.ContentValues;
import java.io.OutputStream;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it.
// Here, sourceBitmap is a Bitmap object representing the file to save to the database.
try {
OutputStream outStream = getContentResolver().openOutputStream(uri);
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
} catch (Exception e) {
Log.e(TAG, "exception while writing image", e);
}
原文请看http://www.bafenbaosoft.com/post/48.html

热点内容
pythonfor多个参数 发布:2025-05-11 01:12:32 浏览:72
plcsfc编程 发布:2025-05-11 01:11:56 浏览:164
安卓手机能删除什么东西 发布:2025-05-11 01:03:55 浏览:413
怎么更改fox存储路径 发布:2025-05-11 01:02:30 浏览:612
忘记账户密码如何恢复出厂设置 发布:2025-05-11 00:51:15 浏览:391
汽车空调压缩机哪种好 发布:2025-05-11 00:51:10 浏览:897
功夫特牛脚本 发布:2025-05-11 00:32:37 浏览:343
autojs脚本代码 发布:2025-05-11 00:32:35 浏览:940
spl编程 发布:2025-05-11 00:25:14 浏览:67
linux搭建android开发环境 发布:2025-05-11 00:18:45 浏览:950