我有一个 videoView,它从与 android 画廊中的视频文件相对应的路径播放视频
VideoView videoView1 = (VideoView)promptsView.findViewById(R.id.videoView09);
String SrcPath = "/storage/emulated/0/DCIM/Camera/20150824_210148.mp4";
videoView1.setVideoPath(SrcPath);
videoView1.requestFocus();
videoView1.start();
Run Code Online (Sandbox Code Playgroud)
现在,我需要以某种方式将此 videoView 中的视频私下存储到我的应用程序的内部存储中。
我已经成功地使用照片来做到这一点
public String saveImageToInternalStorage(Bitmap image, String imgRequestedName) {
ContextWrapper cw = new ContextWrapper(getActivity());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File mypath=new File(directory,imgRequestedName+".jpg");
String loc = mypath.getAbsolutePath();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
image.compress(Bitmap.CompressFormat.JPEG, 70, fos);
SharedPreferences pref = getActivity().getApplicationContext().getSharedPreferences("MyPref", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = pref.edit();
editor.putInt("totalImageCount",(pref.getInt("totalImageCount",0))+1);
editor.commit();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return mypath.getAbsolutePath();
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能对视频做同样的事情? …
我有画廊小部件包含1-10张图片要滑动.我知道当我对屏幕进行条纹处理时,图像会从左向右滚动.我希望自动循环画廊10后自动启动第一张图像,是否有任何自动循环适配器或方式???
final Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
Animation animation = AnimationUtils.loadAnimation(this,
R.anim.rotate_indefinitely);
animation.getInterpolator();
animation.setDuration(1000);
animation.setStartOffset(200);
animation.setRepeatMode(2);
animation.setFillAfter(false);
animation.setFillEnabled(true);
g.setAnimation(animation);
g.startAnimation(animation);
Run Code Online (Sandbox Code Playgroud)
但我只看到第一张图片是动画的..
看看我的视频 ......
我是一名没有Java经验的Flash开发人员,刚开始学习android开发.我正在尝试制作一个简单的孩子的闪存卡应用程序,包括大量的动物图像,以及他们制作的大量声音.
目前我在图库视图中有图像,将它们存储在一个数组中.我也有一系列的声音.因此,每个图像和相应的声音都在阵列中的相同位置,因此很容易为正确的图像播放正确的声音.
现在我想要洗牌,以便每次启动应用程序时它们以不同的顺序出现.我设法将数组随机排列,但是将图像和声音保持在每个阵列的相同位置,但我觉得这变得混乱,我确信这不是解决这个问题的最佳方法.
如果这是一部flash电影,我会使用对象链接图像和声音并将对象粘贴在一个数组中.任何人都可以帮我一些代码,这将实现Android的相同的东西?请记住,我是一个完全熟悉Java的人,并且已经掌握了与AS3相同的教程和基本概念.
我已经以LinearLayout areaForGalleries编程方式Gallery一个接一个地填充了组件.onItemClick每个库中的方法将其从中移除areaForGalleries并将其添加到RelativeLayout parentLayout其中areaForGalleries.见下面的代码.
LinearLayout areaForGalleries;
RelativeLayout parentLayout;
...
private void showGallery() {
final CustomGallery mGallery = new CustomGallery(mContext);
mGallery.setOnItemClickListener(new CustomAdapterView.OnItemClickListener() {
public void onItemClick(CustomAdapterView<?> parent, View v, int position, long id) {
areaForGalleries.removeView(mGallery);
parentLayout.addView(mGallery);
}
});
Run Code Online (Sandbox Code Playgroud)
CustomGallery是我的Android Gallery组件实现.我只更改了左侧图库的对齐方式 - 一行代码已更改.代码在Android 2.1 - 2.3.3上完美运行,但是当在Honeycomb或ICS上尝试时,它崩溃并出现以下错误:
01-31 10:31:49.596: E/AndroidRuntime(1536): FATAL EXCEPTION: main
01-31 10:31:49.596: E/AndroidRuntime(1536): java.lang.NullPointerException
01-31 10:31:49.596: E/AndroidRuntime(1536): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:587)
01-31 10:31:49.596: E/AndroidRuntime(1536): at com.my.example.pullrefreshgallery.CustomGallery.onTouchEvent(CustomGallery.java:812)
01-31 10:31:49.596: E/AndroidRuntime(1536): …Run Code Online (Sandbox Code Playgroud) android add nullpointerexception android-gallery android-3.0-honeycomb
我正在使用图库选取器从图库中选取图像.照相机以纵向模式拍摄的照片在照片库中显示为笔直.但是当我导入照片时,我将照片旋转(横向).只有画廊显示这张照片是直的.如何管理这个问题?我希望所有照片都是它的实际方向.提前致谢
private void addImageFromGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),
GALLERY_CODE);
}
Run Code Online (Sandbox Code Playgroud) 我刚刚为iOS编写了一个带有漂亮照片库的应用程序,现在我想用我的Android应用程序版本做同样的事情.我看到Android Gallery API允许我构建一个滚动的图像库.但我真正想要的是一个带有缩略图网格的苹果照片库样式界面,当点击时,打开所选图像的全屏显示,并允许我使用滑动或左/右箭头浏览照片库工具栏.
在iOS中我使用KTPhotoBrowser来实现这个界面,但是我还没能找到类似Android的东西.任何人都可以指向一个库,甚至是一个带有示例代码的教程,它会给我一个这样的界面,而不必自己滚动它?
更新:我发现GridView教程描述了如何将图像缩略图放入网格中,似乎是完美的选择.Gallery API可用于全尺寸照片浏览器,如@ariefbayu示例代码所示(请参阅下面评论中的链接).它与iPhone风格的画廊并不完全相同,但它非常好.
嘿,我一直在寻找一段时间.以下代码从android库中选择图像并在imageView中显示.但事实上,只要应用程序关闭并重新启动,就必须再次选择.我想知道如何编辑以下内容以在imageView中保存图像.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中尝试做的是让用户从他手机的图库中选择一张图片(不想只获取图库图片,还允许用户选择他们选择的应用程序).我正在使用的代码如下:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
Run Code Online (Sandbox Code Playgroud)
EXTRA_LOCAL_ONLY仅告知接收应用程序它应该只返回存在的数据.
添加intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);上面的代码后,它隐藏了谷歌驱动器应用程序和picasa应用程序,但仍显示谷歌照片(这些照片不在我的设备中.)
此外,我只为本地文件尝试了Android图像选择器,但它隐藏了所有具有远程图像的应用程序,不包括谷歌照片.
注意:所有图像路径都是正确的,因为我在KitKat上的Android Gallery为Intent.ACTION_GET_CONTENT返回不同的Uri(感谢@Paul Burke),但我不想选择互联网/远程图像.
所以我的问题是否有任何方法隐藏谷歌照片应用程序,只从本地设备选择图像.或谷歌照片是否属于Intent.EXTRA_LOCAL_ONLY
从图库中选择视频
我正在尝试以下代码从手机的图库中获取视频:
Intent mediaChooser = new Intent(Intent.ACTION_GET_CONTENT);
mediaChooser.setType("video/*, images/*");
startActivityForResult(mediaChooser, RESULT_LOAD_IMAGE);
Run Code Online (Sandbox Code Playgroud)
我的问题是我收到一条错误消息,说它无法解决符号“ RESULT_LOAD_IMAGE”,有什么想法吗?可能输入清单文件吗?
我想通过拍摄布局的屏幕截图将我的框架布局保存到图库中.这段代码适用于一个项目(名称:试用版),但当我在其他项目(名称:Fg)上尝试相同的代码时,它无效.照片未保存在图库中.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_background);
}
public Bitmap click(View view) {
FrameLayout memecontentView =(FrameLayout) findViewById(R.id.my);
View view1 = memecontentView;
Bitmap b = Bitmap.createBitmap(view1.getWidth(), view1.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
view1.draw(canvas);
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.free_tiket)+".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b,
"Screen", "screen");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) android ×10
android-gallery ×10
add ×1
file-io ×1
gallery ×1
object ×1
random ×1
shuffle ×1
thumbnails ×1
video ×1