如何制作画廊?
How to make a gallery?
你好 :) 我花了几个月的时间来解决这个问题,我已经阅读了文档。
https://creativesdk.adobe.com/docs/android/#/articles/gettingstarted/index.html
图像连接到 url :/
我想知道如何做一个画廊,用户可以select图像,这样你就可以编辑,相机也是如此。
你可以从google图库中学习,这里是源代码https://android.googlesource.com/platform/packages/apps/Gallery2/
启动图库
如果您想从设备的图库中选择图片,您可以这样做:
Intent galleryPickerIntent = new Intent();
galleryPickerIntent.setType("image/*");
galleryPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryPickerIntent, "Select an Image"), 203); // Can be any int
这将启动一个新的 activity,我们希望它能给我们某种结果(在本例中,它将是一个图像 Uri
)。
一个常见的用例是在用户单击按钮时启动图库:
View.OnClickListener openGalleryButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryPickerIntent = new Intent();
galleryPickerIntent.setType("image/*");
galleryPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryPickerIntent, "Select an Image"), 203); // Can be any int
}
};
mOpenGalleryButton.setOnClickListener(openGalleryButtonListener);
此代码将直接打开图库,或者首先向用户显示一个选择器,让他们select将哪个应用程序用作图像源。
收到结果
要接收用户 select 的图像,我们将使用 onActivityResult()
方法:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mAuthSessionHelper.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 203) { // the int we used for startActivityForResult()
// You can do anything here. This is just an example.
mSelectedImageUri = data.getData();
mSelectedImageView.setImageURI(mSelectedImageUri);
}
}
我在 if
块中放置了一些示例代码,但是您在那里做什么将取决于您的应用程序。
你好 :) 我花了几个月的时间来解决这个问题,我已经阅读了文档。
https://creativesdk.adobe.com/docs/android/#/articles/gettingstarted/index.html
图像连接到 url :/
我想知道如何做一个画廊,用户可以select图像,这样你就可以编辑,相机也是如此。
你可以从google图库中学习,这里是源代码https://android.googlesource.com/platform/packages/apps/Gallery2/
启动图库
如果您想从设备的图库中选择图片,您可以这样做:
Intent galleryPickerIntent = new Intent();
galleryPickerIntent.setType("image/*");
galleryPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryPickerIntent, "Select an Image"), 203); // Can be any int
这将启动一个新的 activity,我们希望它能给我们某种结果(在本例中,它将是一个图像 Uri
)。
一个常见的用例是在用户单击按钮时启动图库:
View.OnClickListener openGalleryButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryPickerIntent = new Intent();
galleryPickerIntent.setType("image/*");
galleryPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryPickerIntent, "Select an Image"), 203); // Can be any int
}
};
mOpenGalleryButton.setOnClickListener(openGalleryButtonListener);
此代码将直接打开图库,或者首先向用户显示一个选择器,让他们select将哪个应用程序用作图像源。
收到结果
要接收用户 select 的图像,我们将使用 onActivityResult()
方法:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mAuthSessionHelper.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 203) { // the int we used for startActivityForResult()
// You can do anything here. This is just an example.
mSelectedImageUri = data.getData();
mSelectedImageView.setImageURI(mSelectedImageUri);
}
}
我在 if
块中放置了一些示例代码,但是您在那里做什么将取决于您的应用程序。