gpt4 book ai didi

java - 如何在 Android Activity 中从位图创建 Blob?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:48 26 4
gpt4 key购买 nike

我正在尝试创建新的 MyImage,如 How to upload and store an image with google app engine 中所列.

现在我没有使用任何表单。我有从 Gallery 获取 Uri 的 Android 应用程序:

m_galleryIntent = new Intent();
m_galleryIntent.setType("image/*");
m_galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

m_profileButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivityForResult(Intent.createChooser(m_galleryIntent, "Select Picture"),1);
}
});

我正在使用 Uri 创建位图。
如何从位图中在我的客户端中创建一个 Blob?
我必须将哪些 jar 添加到我的 android 项目中?

这是使用 Blob 的正确方法吗?
我的主要目标是在 GAE 数据存储中保存从 android 上传的图像,是否正确使用此工具或更好的方法?那就是。

最佳答案

您必须将Bitmap 转换为byte[],然后才能将其作为Blob 存储在数据库中。

要将 Bitmap 转换为 byte[],您可以使用:

Bitmap yourBitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
yourBitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bArray = bos.toByteArray();

我希望这是你想要的。

关于java - 如何在 Android Activity 中从位图创建 Blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10618325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com