本文介绍了Android的照片库从Amazon S3的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林旨在创造一个Android应用程序,允许我从我的亚马逊实例收集图像,然后通过横向他们像一个图片库滚动。

Im aiming to create an Android app that allows me to gather images from my Amazon instance and then scroll horizontally through them like a photo gallery.

目前,香港专业教育学院得到了通过碎片滚动的应用程序,但林不知道如何把这些片段内imageviews

Ive currently got an app that scrolls through fragments, but im not sure how to place imageviews inside these fragments

林相对较新的到Android,因此如果有任何图书馆的使用,以帮助完成这个任务不知道?或者是有没有办法从实例下载图像,将它们放置在imageviews,然后将它们连接到片段?

Im relatively new to Android and so was wondering if there are any library's available that help accomplish this task? Or is there a way to download the images from the instance, place them in imageviews and then attach them to the fragments?

推荐答案

1)下载亚马逊的AWS SDK 。在AWS-Android的SDK的jar库文件添加到项目中。

1) Download the Amazon AWS SDK here. Add the aws-android-sdk jar lib file to your project.

2)去下载。将它添加到你的项目了。 IOUtils将有助于轻松地检索字节数组。

2) Go download this library. Add it to your project too. IOUtils will help retrieve the byte array easily.

3)从去获得AWS的安全凭证,并把它们放在你的code为常数。

3) Go get your Security Credentials from AWS and put them in your code as constants.

4)作为SDK的例子做初始化AmazonS3Client:

4) Initialize the AmazonS3Client as the SDK examples do:

private AmazonS3Client s3Client = new AmazonS3Client(
            new BasicAWSCredentials(AWS_KEY,
                    AWS_SECRET));

5)创建的AsyncTask子类来管理下载一个独立的线程。 。

在doInBackground方法,如果你需要得到图像列表进行检索,可以得到一斗的文件列表,并检查键:

In the doInBackground method, if you need to get a list of images to retrieve, you can get a list of files in a bucket, and examine the keys:

ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(<your bucket name>));
List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
for (S3ObjectSummary summary : objectSummaries) {
    String key = summary.getKey();
    // do something with the key
}

6)然后,加code的这个块下载字节,一个在Bitmap对象扔:

6) Then, add this chunk of code to download the bytes and throw them in a Bitmap object:

S3ObjectInputStream content = s3Client.getObject(<your bucket name>, <the key of the targeted file>).getObjectContent();
byte[] bytes = IOUtils.toByteArray(content);
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

7)大概在onPostExecute或东西从调用,生成位图添加到您的ImageView与imageView.setImageBitmap(位);

7) Probably in the onPostExecute or something called from that, add the generated Bitmap to your ImageView with imageView.setImageBitmap(bitmap);

这篇关于Android的照片库从Amazon S3的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:46