Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:19+00:00 2026-05-27T08:20:19+00:00

I have a gridview where images should be displayed. I have saved all the

  • 0

I have a gridview where images should be displayed. I have saved all the images in databases as blobs. Iam using a hashmap and adding it to arraylist. I also have a title along with each image. My code is as follows:

ArrayList<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>();
        Cursor cr = dbAdapter.fetchAllMenuData();


            HashMap<String, Object> map ;


             cr.moveToFirst();

                int k=0;
                while(!cr.isAfterLast())
                {
                 map= new HashMap<String,Object>();
                 map.put("Image", cr.getBlob(cr.getColumnIndex("Image")));
                 map.put("Title", cr.getString(cr.getColumnIndex("Title")));
                 k++;
                 mylist.add(map);
                 map=null;
                 cr.moveToNext();
                }

        MySimpleAdapter adapter = new MySimpleAdapter(Menu.this, mylist,
                R.layout.menugrid, new String[] { "Title", "Image" },
                new int[] { R.id.item_title, R.id.img });

        list.setAdapter(adapter);

Now, Image is in the form of byte[].

I am using a ViewHolderto set the particular image and title to an item in the gridview. the code is as follows

holder.textView1.setText(mData.get(position).get("Title")
                    .toString());
            // holder.textView2.setText(mData.get(position).get("Description").toString());

            byte[] blob= toByteArray(mData.get(position).get("Image"));
         Bitmap bt=BitmapFactory.decodeByteArray(blob,0,blob.length);
            holder.imageView1.setImageBitmap(bt);  

The problem is the hashmap is like HashMap<String, Object> so i had to a write a method that converts Object to byte array. The method is as follows:

public byte[] toBitmap (Object obj)
    {
      byte[] bytes = null;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      try {
        ObjectOutputStream oos = new ObjectOutputStream(bos); 
        oos.writeObject(obj);
        oos.flush(); 
        oos.close(); 
        bos.close();
        bytes = bos.toByteArray ();
        return  bytes;

      }
      catch (IOException ex) {
       return null; //TODO: Handle the exception
      }

This method is returning byte[] correctly. But, i could convert it into a bitmap
BitmapFactory.decodeByteArray(blob,0,blob.length); returns null. so could not set it to imageview.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:20:20+00:00Added an answer on May 27, 2026 at 8:20 am

    Try this. This might help you.

     byte[] pic=(cursor.getBlob(position));   
      ByteArrayInputStream imageStream = new ByteArrayInputStream(pic);
      Bitmap theImage= BitmapFactory.decodeStream(imageStream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview which displays data for all employees and their images (stored
I'm working on some code which fills a GridView full of images that have
I have an Asp.Net page containing one GridView and a couple of images (google
In my activity i have to show some images. I used gridview in my
I have a GridView with three Button columns that are set up with images.
I have a list that displays a bunch of images in gridview style, the
i have followed GridView in my ASP.Net Page: http://s2.imgimg.de/uploads/14b706b38JPG.jpg It should look like this:
I am using grid view with ImageAdapter to display images. I have two set
I have a GridView with dynamically created image buttons that should fire command events
I have a GridView that displays images (7 columns of images that are 166dp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.