代码之家  ›  专栏  ›  技术社区  ›  Hesam

android:在类中加载图像

  •  3
  • Hesam  · 技术社区  · 14 年前

    我的项目我有一个类,在这个类中,我想访问图片的属性。但我不想在这堂课上表现出来。在这门课上,我只想知道图像的宽度和高度,并做一些数学函数来返回一些东西。

    我的问题是我不知道该怎么处理这张照片。我的照片在可抽出的文件夹里。我编写的代码是,问题是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;
        }
    }
    
    1 回复  |  直到 14 年前
        1
  •  7
  •   Zelimir    14 年前

    存储在应用程序资源中的图像,可以通过android.graphics.Bitmap完全处理

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