首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将avd的SD卡图片存储到android的数据库中?

如何将avd的SD卡图片存储到android的数据库中?
EN

Stack Overflow用户
提问于 2011-05-17 11:57:31
回答 1查看 606关注 0票数 0

我是Android的新手。我刚刚在Android 2.1中创建了一个带有256MB Android-SD卡的AVD。我在里面插入了两张图片。我已经使用DDMS透视图做到了这一点。并且图像现在被存储在SDcard的DCIM文件夹中的文件夹100ANDRO中。现在我想创建一个应用程序,允许用户通过浏览文件夹来选择图像,并且需要将相应的图像保存到数据库android-sqlite中。

有没有人能帮我找个合适的方法呢?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-18 19:36:55

我找到了一种方法来解决这个问题。

我已经为UPLOAD和单击操作创建了一个按钮,如下所示。

代码语言:javascript
复制
    upload.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 1);

        }
    });

我已经覆盖了这个方法和下面的同一个类。

代码语言:javascript
复制
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case 1:
     {
      if (resultCode == RESULT_OK)
      {
        Uri photoUri = data.getData();
        if (photoUri != null)
        {
        try {
              String[] filePathColumn = {MediaStore.Images.Media.DATA};
              Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null); 
         cursor.moveToFirst();
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     String filePath = cursor.getString(columnIndex);
     cursor.close();
     Bitmap bitmap = BitmapFactory.decodeFile(filePath);
     imgView.setImageBitmap(bitmap);
     int size = bitmap.getWidth() * bitmap.getHeight();
     ByteArrayOutputStream out = new ByteArrayOutputStream(size);
     bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
     try {
     out.flush();
     out.close();
     } catch (IOException e) {
     e.printStackTrace();}
     String bb = out.toString();
     byte[] x = out.toByteArray();
     image_value.setTag(x);
     image_value.setText(filePath);
     }catch(Exception e)
      {}
      }
    }
    }

在这里,image_value表示xml文件中的隐藏文本视图。我已经传递了图像位置和字节的值作为文本视图的值和标记。稍后,我将这些字节保存到数据库中,以便稍后显示。它工作得很好。

感谢所有人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6026081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档