BitmapFactory start-up issues with decodeResources and getResources

427 views Asked by At

As seen before by others, I'm also really new in the Android world. I used to program in Python and/or C++. Now I'm trying to learn how to make a nice Android app. I found a nice guide on this website: https://developer.android.com/training/displaying-bitmaps/load-bitmap.html

but Im stuck on the displaying a bitmap step. I cannot find anything about this on the Internet, nor on stackoverflow. In my code I have this part:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;   
BitmapFactory.decodeResource(getResources(),R.drawable.test,options)

Whatever I do, or read on the internet, I cannot remove the following things:

  1. options.inJustDecodeBounds = true; always has a red line under it saying: unexpected token. Also when I type "options", ther is no autocomplete.
  2. BitmapFactory.decodeResource(getResources(),R.drawable.queen_heart,options) says that decodeResource cannot resolve symbol.
  3. BitmapFactory.decodeResource(getResources(),R.drawable.queen_heart,options) says that getResources has an invalid method declaration
  4. When I type BitmapFactory, I can only do "options" as autocomplete.

I use Android Studio 2.2.2

See below my whole code.

package com.example.sjaak.myfirstapp;

import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;

/**
 * Created by sjaak on 22.12.16.
 */

public class PrepLoadImage {
    // Get the dimensions of the image.
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true
    BitmapFactory.decodeResource(getResources(),R.drawable.test,options)
    int imageHeight = options.outHeight;
    int imageWidth = options.outWidth;
    String imageType = options.outMimeType;

    // Fit the image to the screen
    public static int calculateInSampleSize(
            BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            while ((halfHeight / inSampleSize) >= reqHeight
                    && (halfWidth / inSampleSize) >= reqWidth) {
                inSampleSize *= 2;
            }
        }

        return inSampleSize;
    }
}
0

There are 0 answers