Android: Upload image to class

In my project, I have a class that in this class I want to have access to image properties. But I do not want to show it through this class. In this class, I just want to know the width and height of the image and perform some mathematical functions in order to return something.

My problem is that I do not know how to turn to this picture. My photo is in a folder with a choice. The code I wrote is the problem: image = (ImageView) findViewById (R.id.imViewRaw);

import android.view.View;
import android.widget.ImageView;


public class Stego
{
    private ImageView image;
    private int imWidth, imHeight;

    public Stego()
    {
        // Instantiate an ImageView and define its properties
        image = (ImageView)findViewById(R.id.imViewRaw);
        image.setImageResource(R.drawable.tasnim);
        imWidth  = image.getWidth();
        imHeight = image.getHeight();
    }

    public int getImageWidth(){
        return imWidth;
    }

    public int getImageHeight(){
        return imHeight;
    }

    public int getMaxMessageChars(){
        int i = imWidth * imHeight; //Number of Pixels
        i *= 3; //Number of bytes. (Each pixel includes of three RGB bytes)
        i /= 4; //Maximum number of characters to store in the picture

        return i;
    }
}
+3
source share
1 answer

The image that is stored in your application resources, you can fully process through android.graphics.Bitmap

    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.tasnim);
    imWidth = image.getWidth();
    imHeight = image.getHeight();
+7

Source: https://habr.com/ru/post/1777401/


All Articles