Example usage for android.graphics BitmapFactory decodeByteArray

List of usage examples for android.graphics BitmapFactory decodeByteArray

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeByteArray.

Prototype

public static Bitmap decodeByteArray(byte[] data, int offset, int length) 

Source Link

Document

Decode an immutable bitmap from the specified byte array.

Usage

From source file:edu.stanford.mobisocial.dungbeetle.DBIdentityProvider.java

public Contact contactForUser() {
    Cursor c = mHelper.getReadableDatabase().rawQuery("SELECT * FROM " + MyInfo.TABLE, new String[] {});
    try {/*from   w  w w  . j  a v a  2  s. co  m*/
        c.moveToFirst();
        long id = Contact.MY_ID;
        String name = c.getString(c.getColumnIndexOrThrow(MyInfo.NAME));
        String email = c.getString(c.getColumnIndexOrThrow(MyInfo.EMAIL));
        String about = c.getString(c.getColumnIndexOrThrow(MyInfo.ABOUT));
        //hack, make about info the status field of the contact class
        Contact contact = new Contact(id, mPubKeyTag, name, email, 0, 0, false, null, about, null, null, 0);
        byte[] picdata = c.getBlob(c.getColumnIndexOrThrow(MyInfo.PICTURE));
        if (picdata != null) {
            contact.picture = BitmapFactory.decodeByteArray(picdata, 0, picdata.length);
        }
        return contact;
    } finally {
        c.close();
    }
}

From source file:com.adampash.contactSearch.ContactsSearchModule.java

@Kroll.method
private TiBlob fetchThumbnail(int thumbnailId) {
    ContentResolver contentResolver = appContext.getContentResolver();

    String[] PHOTO_BITMAP_PROJECTION = new String[] { ContactsContract.CommonDataKinds.Photo.PHOTO };
    Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, thumbnailId);
    Cursor cursor = contentResolver.query(uri, PHOTO_BITMAP_PROJECTION, null, null, null);

    try {/*from w w  w .jav  a2  s  . c om*/
        Bitmap thumbnail = null;
        if (cursor.moveToFirst()) {
            byte[] thumbnailBytes = cursor.getBlob(0);
            if (thumbnailBytes != null) {
                thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length);
            }
        }
        /* return thumbnail; */
        return TiBlob.blobFromImage(thumbnail);
    } finally {
        cursor.close();
    }

}

From source file:com.amanmehara.programming.android.activities.ProgramActivity.java

private void setLanguageDatails() {
    TextView name = (TextView) findViewById(R.id.language_name);
    name.setText(languageName);/*from   w ww. j av a  2s.  c om*/
    ImageView image = (ImageView) findViewById(R.id.language_image);
    if (Objects.nonNull(logoBlob)) {
        int imageBlobLength = logoBlob.length;
        Bitmap logo = BitmapFactory.decodeByteArray(logoBlob, 0, imageBlobLength);
        image.setImageBitmap(logo);
    } else {
        image.setImageResource(R.drawable.ic_circle_logo);
    }
}

From source file:com.ravi.apps.android.newsbytes.DetailsActivity.java

/**
 * Creates the starting views required for the shared element transition.
 *//*from  w ww  . j a va  2 s  .c o m*/
private void createTransitionStartViews(Bundle bundle) {
    // Create the view objects.
    mThumbnailView = new ImageView(this);
    mHeadlineView = new TextView(this);

    // Set the thumbnail view parameters.
    mThumbnailView.setX(bundle.getFloat(MainActivity.IMAGE_XPOS));
    mThumbnailView.setY(bundle.getFloat(MainActivity.IMAGE_YPOS));
    byte[] thumbnailByteStream = bundle.getByteArray(MainActivity.IMAGE);
    if (thumbnailByteStream != null && thumbnailByteStream.length != 0) {
        // Get the thumbnail bitmap from byte array.
        Bitmap thumbnailBitmap = BitmapFactory.decodeByteArray(thumbnailByteStream, 0,
                thumbnailByteStream.length);

        // Set the thumbnail bitmap into the image view.
        if (thumbnailBitmap != null) {
            mThumbnailView.setImageBitmap(thumbnailBitmap);
            mThumbnailView.setScaleType(ImageView.ScaleType.FIT_XY);
        }
    }

    // Set the thumbnail view parameters.
    mHeadlineView.setX(bundle.getFloat(MainActivity.TEXT_XPOS));
    mHeadlineView.setY(bundle.getFloat(MainActivity.TEXT_YPOS));
    mHeadlineView.setText(bundle.getString(MainActivity.TEXT));
}

From source file:com.example.sergey.currentweather.ui.fragment.DetailFragment.java

public void convertImage(final Weather result) {
    Bitmap bitmap = BitmapFactory.decodeByteArray(result.getIconArray(), 0, result.getIconArray().length);
    if (bitmap != null) {
        weatherImage.setImageBitmap(bitmap);
    }/*from ww w  .  jav a2  s. c  o  m*/
}

From source file:br.com.GUI.perfil.MeusAlunos.java

public void atualizarInterface() {
    listDataHeader = new ArrayList<RowItemAluno>();

    if (alunos.isEmpty()) {
        Log.i("alunos", "esta vazio");
    } else {//  w ww  . java  2s .  c o  m
        Log.i("aluno", "nao esta vazio");
    }

    List<RowItemExpandedAluno> opcoes = prepararOpcoes();

    for (Aluno a : alunos) {

        byte[] foto = new Aluno().buscarFotoAluno(b, a.getUsuario());
        Bitmap bmp = BitmapFactory.decodeByteArray(foto, 0, foto.length);

        RowItemAluno item = new RowItemAluno();
        item.setImagemPerfil(bmp);
        item.setNomePerfil(a.getNome());
        item.setUsuarioAluno(a.getUsuario());

        listDataHeader.add(item);

    }

    for (RowItemAluno row : listDataHeader) {
        listDataChild.put(row, opcoes);
    }
    /*CustomAdapterAluno adapter = 
    new CustomAdapterAluno(getActivity(),alunosPerfil);
    meusAlunos.setAdapter(adapter);
            
    meusAlunos.setOnItemClickListener(new OnItemClickListener() {
               
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
    long arg3) {
               
       String usuario = alunos.get(arg2).getUsuario();         
       Intent intent = new Intent(getActivity(),AdicionarAluno.class);
       intent.putExtra("usuario", usuario);
        startActivity(intent);
            
       }
    });*/

    listAdapter = new CustomAdapterExpandedAluno(getActivity(), listDataHeader, listDataChild);

    expListView.setAdapter(listAdapter);

    expListView.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, final int groupPosition,
                int childPosition, long id) {
            Intent i;
            switch (childPosition) {
            case 0:
                i = new Intent(getActivity(), GerenciarAcompanhamento.class);
                i.putExtra("alunoAcompanhamento", listDataHeader.get(groupPosition).getUsuarioAluno());
                startActivity(i);
                break;
            case 1:
                i = new Intent(getActivity(), NovaAvaliacao.class);
                i.putExtra("alunoAvaliacao", listDataHeader.get(groupPosition).getUsuarioAluno());
                startActivity(i);
                break;
            case 2:
                i = new Intent(getActivity(), PreescreverTreinamento.class);
                i.putExtra("usuario", listDataHeader.get(groupPosition).getUsuarioAluno());
                startActivity(i);
                break;
            case 3:
                i = new Intent(getActivity(), MarcarAula.class);
                i.putExtra("usuario", listDataHeader.get(groupPosition).getUsuarioAluno());
                startActivity(i);
                break;
            case 4:

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
                alertDialog.setTitle("Ateno");
                alertDialog.setMessage("Voc tem certeza que deseja remover este aluno?");
                alertDialog.setIcon(R.drawable.critical);
                alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Aluno a = new Aluno().buscarAlunoEspecifico(b,
                                listDataHeader.get(groupPosition).getUsuarioAluno());
                        if (a.removerAlunoWeb(a.getUsuario()) && a.removerAluno(b)) {
                            Toast.makeText(getActivity(), "Removido com Sucesso", Toast.LENGTH_SHORT).show();
                            // Exclui todas as aulas marcadas com o personal
                            ArrayList<Aula> aulasParaExcluir = new ArrayList<Aula>();

                            aulasParaExcluir = new Aula().buscarAulasPorPersonalWeb(a.getUsuarioPersonal(), "");
                            for (Aula c : aulasParaExcluir) {
                                if (c.excluirAulaWeb() && c.excluirAula(b)) {
                                    Log.i("INFORMAO", "Aulas excluidas com sucesso!");
                                }
                            }
                        } else {
                            Toast.makeText(getActivity(), "Falha ao Remover o aluno", Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }
                });
                alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

                alertDialog.show();

                break;
            }

            atualizarInterface();

            return false;
        }

    });
}

From source file:com.mk4droid.IMC_Activities.Fragment_Filters.java

/**
 *          OnCreateView //from   www.j a  va  2 s.c  o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ctx = this.getActivity();
    resources = setResources();
    FActivity_TabHost.IndexGroup = 3;

    v = inflater.inflate(R.layout.fragment_filters, container, false);

    dialogFiltersCh = new ProgressDialog(ctx);
    FiltInflater = inflater;

    //--------- Categories: Separate Parents (or Groups) from Children ----------------
    int NCategs = Service_Data.mCategL.size();
    ArrayList<String> ParentsL = new ArrayList<String>();
    ArrayList<Integer> ParentsL_index = new ArrayList<Integer>();
    ArrayList<Boolean> ParentsL_values = new ArrayList<Boolean>();
    ArrayList<Bitmap> ParentsL_Bitmaps = new ArrayList<Bitmap>();

    // Find Parents 
    for (int i = 0; i < NCategs; i++) {
        if (Service_Data.mCategL.get(i)._level == 1) {
            ParentsL.add(Service_Data.mCategL.get(i)._name);
            ParentsL_values.add(Service_Data.mCategL.get(i)._visible == 1);
            ParentsL_index.add(Service_Data.mCategL.get(i)._id);
            byte[] ic = Service_Data.mCategL.get(i)._icon;
            ParentsL_Bitmaps.add(BitmapFactory.decodeByteArray(ic, 0, ic.length));
        }
    }

    NParents = ParentsL_values.size();

    groups = new String[NParents];
    groups_check_values = new boolean[NParents];
    groups_icon_values = new Drawable[NParents];
    groups_id = new int[NParents];

    for (int i = 0; i < NParents; i++) {
        groups[i] = ParentsL.get(i);
        groups_check_values[i] = ParentsL_values.get(i);

        groups_icon_values[i] = new BitmapDrawable(ParentsL_Bitmaps.get(i));
        groups_id[i] = ParentsL_index.get(i);
    }

    //------------- Children -------------------------------
    ChildrenL = new ArrayList<ArrayList<String>>();
    ArrayList<ArrayList<Boolean>> ChildrenC = new ArrayList<ArrayList<Boolean>>();
    ArrayList<ArrayList<Drawable>> ChildrenD = new ArrayList<ArrayList<Drawable>>();
    ArrayList<ArrayList<Integer>> ChildrenID = new ArrayList<ArrayList<Integer>>();

    for (int iParentSerial = 0; iParentSerial < NParents; iParentSerial++) {
        int IndexParent = ParentsL_index.get(iParentSerial);

        ChildrenL.add(new ArrayList<String>());
        ChildrenC.add(new ArrayList<Boolean>());
        ChildrenD.add(new ArrayList<Drawable>());
        ChildrenID.add(new ArrayList<Integer>());

        for (int i = 0; i < NCategs; i++) {
            if (Service_Data.mCategL.get(i)._parentid == IndexParent) {
                ChildrenL.get(iParentSerial).add(Service_Data.mCategL.get(i)._name);
                ChildrenC.get(iParentSerial).add(Service_Data.mCategL.get(i)._visible == 1);

                byte[] ic = Service_Data.mCategL.get(i)._icon;

                ChildrenD.get(iParentSerial)
                        .add(new BitmapDrawable(BitmapFactory.decodeByteArray(ic, 0, ic.length)));

                ChildrenID.get(iParentSerial).add(Service_Data.mCategL.get(i)._id);
            }
        }
    }

    children = new String[NParents][];
    children_check_values = new boolean[NParents][];
    children_icon_values = new Drawable[NParents][];
    children_id = new int[NParents][];

    for (int i = 0; i < NParents; i++) {
        int NChildren = ChildrenL.get(i).size();
        children[i] = new String[NChildren];
        children_check_values[i] = new boolean[NChildren];
        children_icon_values[i] = new Drawable[NChildren];
        children_id[i] = new int[NChildren];

        for (int j = 0; j < NChildren; j++) {
            children[i][j] = ChildrenL.get(i).get(j).toString();
            children_check_values[i][j] = ChildrenC.get(i).get(j);
            children_icon_values[i][j] = ChildrenD.get(i).get(j);
            children_id[i][j] = ChildrenID.get(i).get(j);
        }
    }

    //------------
    btSelectAllFilters = (Button) v.findViewById(R.id.btSelectAllFilters);
    btReverseAllFilters = (Button) v.findViewById(R.id.btReverseAllFilters);

    //-------- List View- ------------------------
    llfilters = (LinearLayout) v.findViewById(R.id.llfilters);

    //------------ Set All other categories --------
    elv = (ExpandableListView) v.findViewById(R.id.elvMain);
    adapter_explist = new FilterCateg_ExpandableListAdapter(elv, llfilters);

    // -------- Exp List View -----------
    elv.setAdapter(adapter_explist);

    // expand children with 1 child so as to remove expander icon 
    for (int i = 0; i < NParents; i++) {
        if (ChildrenL.get(i).size() == 0) {
            elv.expandGroup(i);
        }
    }

    //----------- Radio button for State Categories ---------
    ctv_Open = (CheckedTextView) v.findViewById(R.id.ctv_Open);
    ctv_Ack = (CheckedTextView) v.findViewById(R.id.ctv_Ack);
    ctv_Closed = (CheckedTextView) v.findViewById(R.id.ctv_Closed);

    ctv_Open.setChecked(OpenSW);
    ctv_Ack.setChecked(AckSW);
    ctv_Closed.setChecked(ClosedSW);

    ctv_Open.setOnClickListener(this);
    ctv_Ack.setOnClickListener(this);
    ctv_Closed.setOnClickListener(this);

    ctv_Open.setText(resources.getString(R.string.OpenIssue));
    ctv_Ack.setText(resources.getString(R.string.AckIssue));
    ctv_Closed.setText(resources.getString(R.string.ClosedIssue));

    //--------------- Button Reverse All Filters -------------
    btReverseAllFilters.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            FiltersChangedFlag = true;

            //--------- Set DB ----------------
            DatabaseHandler dbHandler = new DatabaseHandler(ctx);
            for (int i = 0; i < NParents; i++) {
                int NChildren = ChildrenL.get(i).size();
                groups_check_values[i] = !groups_check_values[i];
                dbHandler.setCategory(groups_id[i], groups_check_values[i] ? 1 : 0); // Send as integer

                for (int j = 0; j < NChildren; j++) {
                    children_check_values[i][j] = !children_check_values[i][j];
                    dbHandler.setCategory(children_id[i][j], children_check_values[i][j] ? 1 : 0); // Send as integer
                }
            }
            dbHandler.db.close();

            //--------- Set GUI ----------------
            adapter_explist = new FilterCateg_ExpandableListAdapter(elv, llfilters);

            elv.setAdapter(adapter_explist);

            // expand children with 1 child so as to remove expander icon 
            for (int i = 0; i < NParents; i++) {
                if (ChildrenL.get(i).size() == 0) {
                    elv.expandGroup(i);
                }
            }
        }
    });

    //--------------- Button Select All Filters -------------

    //------ Check to see if all inactive --------
    int sumVisible = 0;
    for (int i = 0; i < NCategs; i++)
        sumVisible += Service_Data.mCategL.get(i)._visible;

    if (sumVisible > 0)
        btSelectAllFilters.setTag(false);
    else
        btSelectAllFilters.setTag(true);

    //-------------
    btSelectAllFilters.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            FiltersChangedFlag = true;

            //----- Set DB ---------
            DatabaseHandler dbHandler = new DatabaseHandler(ctx);
            for (int i = 0; i < NParents; i++) {
                int NChildren = ChildrenL.get(i).size();

                groups_check_values[i] = (Boolean) btSelectAllFilters.getTag();

                dbHandler.setCategory(groups_id[i], groups_check_values[i] ? 1 : 0); // Send as integer

                for (int j = 0; j < NChildren; j++) {
                    children_check_values[i][j] = (Boolean) btSelectAllFilters.getTag();
                    dbHandler.setCategory(children_id[i][j], children_check_values[i][j] ? 1 : 0); // Send as integer
                }
            }

            dbHandler.db.close();
            btSelectAllFilters.setTag(!(Boolean) btSelectAllFilters.getTag());

            //------ Set GUI -----
            adapter_explist = new FilterCateg_ExpandableListAdapter(elv, llfilters);
            elv.setAdapter(adapter_explist);

            // expand children with 1 child so as to remove expander icon 
            for (int i = 0; i < NParents; i++) {
                if (ChildrenL.get(i).size() == 0) {
                    elv.expandGroup(i);
                }
            }
        }
    });

    return v;
}

From source file:com.google.identitytoolkit.demo.GitkitDemo.java

private void showAccount(GitkitUser user) {
    ((TextView) findViewById(R.id.account_email)).setText(user.getEmail());

    if (user.getDisplayName() != null) {
        ((TextView) findViewById(R.id.account_name)).setText(user.getDisplayName());
    }//  w w w . j a  v  a  2 s .c  o m

    if (user.getPhotoUrl() != null) {
        final ImageView pictureView = (ImageView) findViewById(R.id.account_picture);
        new AsyncTask<String, Void, Bitmap>() {

            @Override
            protected Bitmap doInBackground(String... arg) {
                try {
                    byte[] result = HttpUtils.get(arg[0]);
                    return BitmapFactory.decodeByteArray(result, 0, result.length);
                } catch (IOException e) {
                    return null;
                }
            }

            @Override
            protected void onPostExecute(Bitmap bitmap) {
                if (bitmap != null) {
                    pictureView.setImageBitmap(bitmap);
                }
            }
        }.execute(user.getPhotoUrl());
    }
}

From source file:com.scm.reader.livescanner.sdk.recognizers.KooabaRecognizer.java

/**
 * Tries to recognize the image. It first performs a rotation of image,
 * then creates new Search object and executes the imageRecognition
 *///from w  w  w  . ja  v  a2 s. c  o  m
//remove this?
public Search sendForRecognition(byte image[]) throws IOException, NoSuchAlgorithmException, JSONException {

    Log.d("KooabaRecognizer", "send for recognition");
    Search search = null;
    ImageRecognizer imageRecognizer = new ImageRecognizer();

    Bitmap img = null;
    img = BitmapFactory.decodeByteArray(image, 0, image.length);

    try {
        img = fixRotation(img);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    search = createNewSearch(img, search);
    return executeSearch(search, imageRecognizer);
}

From source file:com.dalaran.LDCache.java

public synchronized Bitmap getBitmap(String key) {
    Log.d("try get disc cache:", key);
    final Cache.Entry requestedItem = getEntry(key);

    Bitmap bitmap = get(key.hashCode());
    if (bitmap != null) {
        return bitmap;
    }//from  www .  j a  va2s . c om

    if (requestedItem != null) {
        requestedItem.countGet++;
        put(key, requestedItem);
    } else {
        return null;
    }

    return BitmapFactory.decodeByteArray(requestedItem.data, 0, requestedItem.data.length);
}