how to load an image from url in native (cpp) and load it in android

Martin j 09/05/2017. 0 answers, 34 views
android android android-ndk android-ndk jni

i am looking on a research based on loading an image in native cpp side and calling that function in the java class to display that image in my android app.

  • currently i am adding the image by only passing the string (url) from the cpp side.
  • loading image part is done in the java class itself

    private class DownloadImageFromInternet extends AsyncTask<String, Void, Bitmap> {
    ImageView imageView;
    
    public DownloadImageFromInternet(ImageView imageView) {
        this.imageView = imageView;
        Toast.makeText(getApplicationContext(), "Please wait...", Toast.LENGTH_SHORT).show();
    }
    
    protected Bitmap doInBackground(String... urls) {
        String imageURL = urls[0];
        Bitmap bimage = null;
        try {
            InputStream in = new java.net.URL(imageURL).openStream();
            bimage = BitmapFactory.decodeStream(in);
    
        } catch (Exception e) {
            Log.e("Error Message", e.getMessage());
            e.printStackTrace();
        }
        return bimage;
    }
    
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }
    
    
    }

this is my sample code which loads the image in android side

No Answers Yet

Related questions

Hot questions

Language

Popular Tags