Example #1
1
  public static void resizeRotateAndSaveByteArrayToSDCardPath(
      String desiredName, byte[] data, float targetWidth, float targetHeight) {
    /** GET bitmap info * */
    BitmapFactory.Options opts = new Options();
    opts.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(data, 0, data.length, opts);

    /** scale approximately * */
    opts.inJustDecodeBounds = false;
    opts.inSampleSize =
        calculateInSampleSize(opts, Math.round(targetWidth), Math.round(targetHeight));
    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
    data = null;

    /** calculate final WIDTH and HEIGHT (with right aspect ratio) * */
    int originalWidth = bmp.getWidth();
    int originalHeight = bmp.getHeight();
    float scale = (float) targetWidth / (float) originalWidth;
    int newWidth = Math.round(targetWidth);
    int newHeight = Math.round(scale * (float) originalHeight);

    /** resize exactly to desired size * */
    Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true);
    /** rotating * */
    Matrix mtx = new Matrix();
    mtx.preRotate(90);
    /** saving * */
    saveToSDCardPath(
        desiredName,
        Bitmap.createBitmap(
            scaledBmp, 0, 0, scaledBmp.getWidth(), scaledBmp.getHeight(), mtx, true));
  }
Example #2
0
  private void _scaleBitmap() {
    int image_width = this.mBitmap.getWidth();
    int image_height = this.mBitmap.getHeight();
    int new_image_width;
    int new_image_height;
    int _screen_width = 640;

    if (image_width >= image_height) {
      if (image_height < _screen_width) {
        new_image_width =
            (int) ((float) image_width * ((float) _screen_width / (float) image_height));
      } else {
        new_image_width =
            (int) ((float) image_width / ((float) image_height / (float) _screen_width)); // ok
      }
      this.mBitmap = Bitmap.createScaledBitmap(this.mBitmap, new_image_width, _screen_width, true);

    } else if (image_width < image_height) {
      if (image_width < _screen_width) {
        new_image_height =
            (int) ((float) image_height * ((float) _screen_width / (float) image_width));
      } else {
        new_image_height =
            (int) ((float) image_height / ((float) image_width / (float) _screen_width));
      }

      this.mBitmap = Bitmap.createScaledBitmap(mBitmap, _screen_width, new_image_height, true);
    }
  }
Example #3
0
  public void setupVar() {
    moneyPanel = new MoneyPanel(scaledMoneyPanel, 256, 128);
    money = new Money(sulMoney, 312, 64);
    timer = new Timer(sulMoney, 312, 64);
    score11 = new Score(sulMoney, 312, 64);
    score22 = new Score(sulMoney, 312, 64);
    bg = new Background(scaledBg);

    gameWord1 = new GameWord(scaledGameWord, 192, 64, 10, 400, "gameWord1");
    scaledGameWord =
        Bitmap.createScaledBitmap(
            BitmapFactory.decodeResource(getResources(), R.drawable.player1), 192, 64, true);
    gameWord1.setBitmap(scaledGameWord);
    gameWord2 = new GameWord(scaledGameWord, 192, 64, 10, 400, "gameWord2");
    scaledGameWord =
        Bitmap.createScaledBitmap(
            BitmapFactory.decodeResource(getResources(), R.drawable.player2), 192, 64, true);
    gameWord2.setBitmap(scaledGameWord);
    done = new GameWord(scaledDone, 192, 64, 200, 400, "Done");
    player1 = new GameWord(scaledPlayer1, 192, 64, 300, 300, "Player1");
    player2 = new GameWord(scaledPlayer2, 192, 64, 300, 300, "Player2");
    draw = new GameWord(scaledDraw, 192, 64, 300, 300, "Draw");

    mid =
        new Middle(scaledMiddle, (int) (128 / scaleFactorX), (int) (128 / scaleFactorY), 364, 176);
    gameObjectadd();
  }
  private void setLinePositions(GridLayoutView glv) {

    // extend imgageView to bounds
    Bitmap bitmapy = BitmapFactory.decodeResource(getResources(), R.drawable.line_y);
    bitmapy = Bitmap.createScaledBitmap(bitmapy, glWidth, bitmapy.getHeight(), true);
    lineY.setImageBitmap(bitmapy);

    Bitmap bitmapx = BitmapFactory.decodeResource(getResources(), R.drawable.line_x);
    bitmapx = Bitmap.createScaledBitmap(bitmapx, bitmapx.getWidth(), glHeight, true);
    lineX.setImageBitmap(bitmapx);

    xParams = (RelativeLayout.LayoutParams) lineX.getLayoutParams();
    yParams = (RelativeLayout.LayoutParams) lineY.getLayoutParams();

    int positionLineXCentre = glv.getAxisXlines().get(glv.getGridSize() / 2).x;
    xParams.leftMargin =
        shapeStartPointX(glv.getZeroPosX(), glv.getLineSpacingX(), lineStartCoordX)
            - bitmapx.getWidth() / 2;
    lineX.setLayoutParams(xParams);

    int positionLineYCentre = glv.getAxisYlines().get(glv.getGridSize() / 2).y;
    yParams.topMargin =
        shapeStartPointY(glv.getZeroPosY(), glv.getLineSpacingY(), lineStartCoordY)
            - bitmapy.getHeight() / 2;
    lineY.setLayoutParams(yParams);
  }
  public void initView() {
    // bitmap for portrait orientation
    bitmapPort = BitmapFactory.decodeResource(getResources(), R.drawable.all_portrait);
    bitmapPort =
        Bitmap.createScaledBitmap(
            bitmapPort,
            (int) (46 * context.getResources().getDisplayMetrics().density),
            (int) (320 * ratioHeight),
            true);
    scrollPort = BitmapFactory.decodeResource(getResources(), R.drawable.scroller_portrait);
    scrollPort =
        Bitmap.createScaledBitmap(
            scrollPort,
            (int) (10 * context.getResources().getDisplayMetrics().density),
            (int) (16 * ratioHeight),
            true);

    // bitmap for landscape orientation
    bitmapLand = BitmapFactory.decodeResource(getResources(), R.drawable.all_landscape);
    bitmapLand =
        Bitmap.createScaledBitmap(
            bitmapLand,
            (int) (context.getResources().getDisplayMetrics().widthPixels - (53 * ratioWidth)),
            (int) (62 * ratioHeight),
            true);
    scrollLand = BitmapFactory.decodeResource(getResources(), R.drawable.scroller_landscape);
    scrollLand =
        Bitmap.createScaledBitmap(
            scrollLand, (int) (21 * ratioWidth), (int) (13 * ratioHeight), true);
  }
  private boolean check() {
    if (mMenuTitleValue.getText().toString().equals("")
        || mMenuContentValue.getText().toString().equals("")
        || mCookingTimeValue.getText().toString().equals("")) {
      Toast.makeText(AddMenuActivity.this, "Please fill required text fields!", Toast.LENGTH_SHORT)
          .show();
      return false;
    } else if (mDisplayImgView.getDrawable() == null) {
      Toast.makeText(AddMenuActivity.this, "Please upload a display image!", Toast.LENGTH_SHORT)
          .show();
      return false;
    } else {
      //            BitmapFactory.Options options = new BitmapFactory.Options();
      //            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
      mDisPlayBitmap = BitmapFactory.decodeFile(mDisplayImgPath.get(0));

      // Compress img to meet the ParseFile maximum requirements
      if (mDisPlayBitmap.getByteCount() >= 10485760)
        mDisPlayBitmap = Bitmap.createScaledBitmap(mDisPlayBitmap, 1920, 1080, true);
      for (int i = 0; i < mToeRecyclerAdapter.getItemCount(); i++) {
        Bitmap currentImg = BitmapFactory.decodeFile(mImgPaths.get(i));
        if (currentImg.getByteCount() >= 10485760)
          currentImg = Bitmap.createScaledBitmap(currentImg, 1920, 1080, true);
        mImgBitmaps.add(currentImg);
      }
      return true;
    }
  }
    // ----------------------------------
    //  생성자(Constructor)
    // ----------------------------------
    public MyView(Context context) {
      super(context);

      DisplayMetrics disp = getApplicationContext().getResources().getDisplayMetrics();
      width = disp.widthPixels; // View의 가로 폭
      height = disp.heightPixels; // View의 세로 높이

      cx = width / 2;
      cy = height / 2 - 30; // View의 중심보다 위로 이동

      // 배경 이미지를 읽고 View 크기에 맞게 늘려줌
      imgBack = BitmapFactory.decodeResource(context.getResources(), R.mipmap.back);
      imgBack = Bitmap.createScaledBitmap(imgBack, width, height, true);

      // 과녁의 이미지를 280x280으로 설정
      imgTarget = BitmapFactory.decodeResource(context.getResources(), R.mipmap.target1);
      imgTarget = Bitmap.createScaledBitmap(imgTarget, 280, 280, true);

      tw = imgTarget.getWidth() / 2; // 과녁의 중심점
      th = imgTarget.getHeight() / 2;

      mBullet = new ArrayList<Bullet>(); // ArrayList 생성

      mHandler.sendEmptyMessageDelayed(0, 10); // Handler 호출
    }
  // Result from choose image from gallery and take photo
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
      case REQUEST_IMAGE_CAPTURE:
        if (resultCode == Activity.RESULT_OK && data != null) {
          Log.v("prototypev1", "he entrat a capturar fto");
          Bundle extras = data.getExtras();
          Bitmap photo = (Bitmap) extras.get("data");
          newProfilePicture = Bitmap.createScaledBitmap(photo, 80, 80, true);
          new SetProfilePictureTask().execute();
        }
        break;
      case REQUEST_PICK_IMAGE:
        Log.v("prototypev1", "he entrat a triar foto");
        if (resultCode == Activity.RESULT_OK && data != null) {
          Bitmap yourSelectedImage = searchPhotoSelect(data);
          newProfilePicture = Bitmap.createScaledBitmap(yourSelectedImage, 80, 80, true);
          // upload to parse
          new SetProfilePictureTask().execute();
        }
        break;

      default:
        break;
    }
    profilePicture.setImageBitmap(newProfilePicture);
  }
 /** 初始化Bitmap */
 private void createBitmaps() {
   mSky = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sky);
   mSky = Bitmap.createScaledBitmap(mSky, mScreenWidth, mSkyHeight, true);
   mTown = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.buildings);
   mTown = Bitmap.createScaledBitmap(mTown, mScreenWidth, mTownHeight, true);
   mSun = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sun);
   mSun = Bitmap.createScaledBitmap(mSun, mSunSize, mSunSize, true);
 }
  @Override
  public View getView(final int position, View view, ViewGroup parent) {

    final ViewHolder holder;
    if (view == null) {
      view = mInflater.inflate(R.layout.flirt_buzz_single, null);
      holder = new ViewHolder();
      holder.title = (TextView) view.findViewById(R.id.buzz_text1);
      holder.content = (TextView) view.findViewById(R.id.buzz_Ctext);
      holder.time_dis = (TextView) view.findViewById(R.id.buzz_time_dis);
      holder.userPic = (ImageView) view.findViewById(R.id.buzz_userPic);
      holder.contentPic = (ImageView) view.findViewById(R.id.buzz_pic);
      holder.wait = (ProgressBar) view.findViewById(R.id.buzz_wait);
      view.setTag(holder);
    } else {
      holder = (ViewHolder) view.getTag();
    }
    holder.title.setText(data.get(position)[1]); // 顯示文字說明

    if (data.get(position)[3].equals("text")) {
      holder.content.setText(data.get(position)[2]);
      holder.contentPic.setImageBitmap(null);
    } else if (data.get(position)[3].equals("photo")) {
      holder.content.setText("上傳了一張圖片");
      if (ImgCache.IsCache(data.get(position)[2]) == false) {
        ImgCache.LoadUrlPic(data.get(position)[2], h);
      } else if (ImgCache.IsDownLoadFine(data.get(position)[2])
          == true) { // 如果已經下載完成,就顯示圖片並把ProgressBar隱藏
        Bitmap Bmp = ImgCache.getImg(data.get(position)[2]);
        Bmp =
            Bitmap.createScaledBitmap(
                Bmp, 128, (int) (Bmp.getHeight() * 128 / Bmp.getWidth()), true);
        holder.contentPic.setImageBitmap(Bmp);
      } else {
        // 這裡是下載中,什麼事都不用做
      }
    }

    holder.time_dis.setText(data.get(position)[4]);
    holder.userPic.setVisibility(View.INVISIBLE);
    holder.wait.setVisibility(View.VISIBLE);
    if (ImgCache.IsCache(data.get(position)[0]) == false) { // 如果圖片沒有暫存
      ImgCache.LoadUrlPic(data.get(position)[0], h);
    } else if (ImgCache.IsDownLoadFine(data.get(position)[0])
        == true) { // 如果已經下載完成,就顯示圖片並把ProgressBar隱藏
      Bitmap Bmp = ImgCache.getImg(data.get(position)[0]);
      Bmp = Bitmap.createScaledBitmap(Bmp, 64, 64, true);
      holder.userPic.setImageBitmap(Bmp);
      holder.wait.setVisibility(View.GONE);
      holder.userPic.setVisibility(View.VISIBLE);
    } else {
      // 這裡是下載中,什麼事都不用做
    }
    return view;
  }
Example #11
0
  private void init(Context context, AttributeSet attrs) {
    mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    Resources resources = context.getResources();

    // get attrConfiguration
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
    int width = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmWidth, 0);
    int height = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmHeight, 0);
    array.recycle();

    // size width or height
    if (width <= 0 || height <= 0) {
      width = COMMON_WIDTH_IN_PIXEL;
      height = COMMON_HEIGHT_IN_PIXEL;
    } else {
      float scale = (float) COMMON_WIDTH_IN_PIXEL / COMMON_HEIGHT_IN_PIXEL;
      if ((float) width / height > scale) {
        width = (int) (height * scale);
      } else if ((float) width / height < scale) {
        height = (int) (width / scale);
      }
    }

    // get viewConfiguration
    mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    // get Bitmap
    bmBgGreen = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_green);
    bmBgWhite = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_white);
    bmBtnNormal = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_normal);
    bmBtnPressed = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_pressed);

    // size Bitmap
    bmBgGreen = Bitmap.createScaledBitmap(bmBgGreen, width, height, true);
    bmBgWhite = Bitmap.createScaledBitmap(bmBgWhite, width, height, true);
    bmBtnNormal = Bitmap.createScaledBitmap(bmBtnNormal, height, height, true);
    bmBtnPressed = Bitmap.createScaledBitmap(bmBtnPressed, height, height, true);

    bmCurBtnPic = bmBtnNormal; // 初始按钮图片
    bmCurBgPic = mChecked ? bmBgGreen : bmBgWhite; // 初始背景图片
    bgWidth = bmBgGreen.getWidth(); // 背景宽度
    bgHeight = bmBgGreen.getHeight(); // 背景高度
    btnWidth = bmBtnNormal.getWidth(); // 按钮宽度
    offBtnPos = 0; // 关闭时在最左边
    onBtnPos = bgWidth - btnWidth; // 开始时在右边
    curBtnPos = mChecked ? onBtnPos : offBtnPos; // 按钮当前为初始位置

    // get density
    float density = resources.getDisplayMetrics().density;
    mVelocity = (int) (VELOCITY * density + 0.5f); // 动画距离
    mSaveLayerRectF = new RectF(0, 0, bgWidth, bgHeight);
  }
  private void resize() {

    float wratio = (int) thumbnail.getWidth() / 640;
    float hratio = (int) thumbnail.getHeight() / 800;
    if (thumbnail.getWidth() > 640) {
      thumbnail =
          Bitmap.createScaledBitmap(thumbnail, 640, (int) (thumbnail.getHeight() / wratio), false);
    } else if (thumbnail.getHeight() > 800) {
      thumbnail =
          Bitmap.createScaledBitmap(thumbnail, (int) (thumbnail.getWidth() / hratio), 800, false);
    }
  }
    // Surface view requires that all elements are drawn completely
    private void drawCircles(Canvas canvas, List<MyPoint> circles) {

      // canvas.drawColor(Color.WHITE);
      bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
      heartbitmap = Bitmap.createScaledBitmap(heartbitmap, 70, 70, true);
      canvas.drawBitmap(bitmap, 0, 20, null);

      for (MyPoint point : circles) {
        // canvas.drawCircle(point.x, point.y, 20.0f, paint);
        canvas.drawBitmap(heartbitmap, point.x, point.y, null);
      }
    }
Example #14
0
  public Cano(Context context, Tela tela, int posicao) {
    this.tela = tela;
    this.posicao = posicao;
    this.alturaDoCanoInferior = tela.getAltura() - TAMANHO_DO_CANO - valorAleatorio();
    this.alturaDoCanoSuperior = 0 + TAMANHO_DO_CANO + valorAleatorio();

    Bitmap bp = BitmapFactory.decodeResource(context.getResources(), R.drawable.cano);
    this.canoInferior =
        Bitmap.createScaledBitmap(bp, LARGURA_DO_CANO, this.alturaDoCanoInferior, false);
    this.canoSuperior =
        Bitmap.createScaledBitmap(bp, LARGURA_DO_CANO, this.alturaDoCanoSuperior, false);
  }
Example #15
0
  private void createBitmaps() {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.RGB_565;

    mSky = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sky, options);
    mSky = Bitmap.createScaledBitmap(mSky, mScreenWidth, mSkyHeight, true);
    mTown =
        BitmapFactory.decodeResource(getContext().getResources(), R.drawable.buildings, options);
    mTown = Bitmap.createScaledBitmap(mTown, mScreenWidth, (int) (mScreenWidth * TOWN_RATIO), true);
    mSun = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.sun, options);
    mSun = Bitmap.createScaledBitmap(mSun, mSunSize, mSunSize, true);
  }
Example #16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.skinresult1);

    image1 = (ImageView) findViewById(R.id.image1);
    image2 = (ImageView) findViewById(R.id.image2);
    image3 = (ImageView) findViewById(R.id.image3);
    image4 = (ImageView) findViewById(R.id.image4);

    int width = 400;
    int height = 370;
    Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.apimage1);
    Bitmap bmp2 = BitmapFactory.decodeResource(getResources(), R.drawable.apimage2);
    Bitmap bmp3 = BitmapFactory.decodeResource(getResources(), R.drawable.apimage3);
    Bitmap bmp4 = BitmapFactory.decodeResource(getResources(), R.drawable.apimage4);

    Bitmap resizedbitmap1 = Bitmap.createScaledBitmap(bmp1, width, height, true);
    Bitmap resizedbitmap2 = Bitmap.createScaledBitmap(bmp2, width, height, true);
    Bitmap resizedbitmap3 = Bitmap.createScaledBitmap(bmp3, width, height, true);
    Bitmap resizedbitmap4 = Bitmap.createScaledBitmap(bmp4, width, height, true);
    image1.setImageBitmap(resizedbitmap1);
    image2.setImageBitmap(resizedbitmap2);
    image3.setImageBitmap(resizedbitmap3);
    image4.setImageBitmap(resizedbitmap4);

    animationSlideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
    animationSlideOutRight = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
    animationSlideInLeft.setDuration(2000);
    animationSlideOutRight.setDuration(4000);
    animationSlideInLeft.setAnimationListener(animationSlideInLeftListener);
    animationSlideOutRight.setAnimationListener(animationSlideOutRightListener);

    curSlidingImage = image1;
    image1.startAnimation(animationSlideInLeft);
    image1.setVisibility(View.VISIBLE);

    Button button2 = (Button) findViewById(R.id.go_buy);
    button2.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent openBrowser =
                new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse(
                        "http://www.amorepacificmall.com/main.do?source=https://www.google.co.kr/"));
            startActivity(openBrowser);
          }
        });
  }
Example #17
0
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    // 初始化宽度
    mPanelWidth = w;
    // 初始化行高
    mLineHeight = mPanelWidth * 1.0f / MAX_LINE;
    // 改变棋子的size
    int pieceWidth = (int) (mLineHeight * ratioPieceOfLineHeight);
    mWhitePiece = Bitmap.createScaledBitmap(mWhitePiece, pieceWidth, pieceWidth, false);
    mBlackPiece = Bitmap.createScaledBitmap(mBlackPiece, pieceWidth, pieceWidth, false);

    //        Log.d(TAG, "onSizeChanged: " + w);
  }
Example #18
0
        public void handleMessage(android.os.Message msg) {

          if (msg.what == 1 || msg.what == 2) {
            if (isOneShow) {
              layoutConnPrompt.setVisibility(View.GONE);
              isOneShow = false;
            }
          }
          switch (msg.what) {
            case 1:
              { // h264
                textTimeStamp.setText(timeShow);
                myRender.writeSample(videodata, nVideoWidth, nVideoHeight);
                playImg.setVisibility(View.GONE);
                int width = getWindowManager().getDefaultDisplay().getWidth();

                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, width * 3 / 4);
                lp.gravity = Gravity.CENTER;
                myGlSurfaceView.setLayoutParams(lp);
              }
              break;
            case 2:
              { // jpeg
                textTimeStamp.setText(timeShow);
                Bitmap bmp = BitmapFactory.decodeByteArray(videodata, 0, videoDataLen);
                if (bmp == null) {
                  return;
                }
                Bitmap bitmap = null;
                int width = getWindowManager().getDefaultDisplay().getWidth();
                int height = getWindowManager().getDefaultDisplay().getHeight();
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, width * 3 / 4);
                lp.gravity = Gravity.CENTER;
                playImg.setLayoutParams(lp);
                if (getResources().getConfiguration().orientation
                    == Configuration.ORIENTATION_PORTRAIT) {
                  bitmap = Bitmap.createScaledBitmap(bmp, width, width * 3 / 4, true);
                } else if (getResources().getConfiguration().orientation
                    == Configuration.ORIENTATION_LANDSCAPE) {
                  bitmap = Bitmap.createScaledBitmap(bmp, width, height, true);
                }
                playImg.setVisibility(View.VISIBLE);
                playImg.setImageBitmap(bitmap);
              }
              break;
            default:
              break;
          }
        }
Example #19
0
  @Override
  public void updateScale(double scale) {
    super.updateScale(scale);
    mFrame1Scaled =
        Bitmap.createScaledBitmap(
            mFrame1, (int) (mFrame1.getWidth() * scale), (int) (mFrame1.getHeight() * scale), true);

    mFrame2Scaled =
        Bitmap.createScaledBitmap(
            mFrame2, (int) (mFrame2.getWidth() * scale), (int) (mFrame2.getHeight() * scale), true);

    mFrame3Scaled =
        Bitmap.createScaledBitmap(
            mFrame3, (int) (mFrame3.getWidth() * scale), (int) (mFrame3.getHeight() * scale), true);
  }
  /**
   * Obsluga wyników pracy z dialogem
   *
   * @param requestCode tag do rozpoznania jak uzyskano zdjęcie
   * @param resultCode tag czy praca z dialogem przeszla pomyślnie
   * @param data zwrócone dane w wyniku pracy z dialogem
   * @return para Obrazku i jego nazwy
   */
  public Pair<Bitmap, String> onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
      if (requestCode == REQUEST_CAMERA) {
        File f = new File(Environment.getExternalStorageDirectory().toString());
        for (File temp : f.listFiles()) {
          if (temp.getName().equals("temp.jpg")) {
            f = temp;
            break;
          }
        }
        try {
          Bitmap bm;
          BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
          bm = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions);

          bm = Bitmap.createScaledBitmap(bm, 250, 250, true);
          f.delete();
          return new Pair<Bitmap, String>(bm, "photo");
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else if (requestCode == SELECT_FILE) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor =
            mContext.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();

        int pathColumnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(pathColumnIndex);
        cursor.close();

        Uri filePathUri;
        filePathUri = Uri.parse(filePath);
        String fileName = filePathUri.getLastPathSegment();

        Bitmap bm;
        BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bm = BitmapFactory.decodeFile(filePath, bitmapOptions);

        bm = Bitmap.createScaledBitmap(bm, 250, 250, true);

        return new Pair<Bitmap, String>(bm, fileName);
      }
    }
    return null;
  }
  @SuppressLint("DrawAllocation")
  @Override
  public void onDraw(Canvas canvas) {
    // load the bitmap
    loadBitmap();

    // init shader
    if (image != null) {
      shader =
          new BitmapShader(
              Bitmap.createScaledBitmap(image, canvas.getWidth(), canvas.getHeight(), false),
              Shader.TileMode.CLAMP,
              Shader.TileMode.CLAMP);
      paint.setShader(shader);
      int circleCenter = viewWidth / 2;

      // circleCenter is the x or y of the view's center
      // radius is the radius in pixels of the cirle to be drawn
      // paint contains the shader that will texture the shape
      canvas.drawCircle(
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          circleCenter + borderWidth,
          paintBorder);
      canvas.drawCircle(
          circleCenter + borderWidth, circleCenter + borderWidth, circleCenter, paint);
    }
  }
  public String saveImage(Uri image, int width, int height) {
    String imagePath = null;
    try {

      byte[] data = readFileThroughUri(image);
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.outWidth = height;
      options.outHeight = width;
      options.inSampleSize = 2;
      Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, options);
      Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, width, height, false);
      bmp.recycle();
      bmp = null;
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      scaledBmp.compress(
          Bitmap.CompressFormat.JPEG,
          (int) (100 * ImageFileManipulation.IAMGE_COMPRESSION_RATIO),
          bytes);
      imagePath = ImageFileManipulation.EXTERNAL_MEMORY + getFileName() + ".jpeg";
      boolean isFileCreate = createFileInData(imagePath, bytes.toByteArray());
      if (!isFileCreate) // if file is not created return null
      return null;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return imagePath;
  }
Example #23
0
  /**
   * @param bmp
   * @param radius
   * @return
   */
  public static Bitmap getCroppedBitmap(Bitmap bmp, float radius) {
    Bitmap sbmp;
    int width = (int) radius;
    if (bmp.getWidth() != width || bmp.getHeight() != width) {
      sbmp = Bitmap.createScaledBitmap(bmp, width, width, false);
    } else {
      sbmp = bmp;
    }
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);
    return output;
  }
 private Drawable resizeSmall(Drawable image) {
   {
     Bitmap d = ((BitmapDrawable) image).getBitmap();
     Bitmap bitmapOrig = Bitmap.createScaledBitmap(d, 200, 200, false);
     return new BitmapDrawable(bitmapOrig);
   }
 }
Example #25
0
  public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
      sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 255, 255, 255);
    paint.setColor(Color.parseColor("#7f97d2"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f,
        sbmp.getHeight() / 2 + 0.7f,
        sbmp.getWidth() / 2 - strokeWidth,
        paint); // 2-9f
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    //        Paint pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
    //	    pTouch.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    //	    pTouch.setAlpha(255);
    //	    pTouch.setColor(Color.TRANSPARENT);
    //	    pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));

    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, ((float)
    // Math.ceil((sbmp.getHeight()+15)/11))+.2f, pTouch);
    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, 57, pTouch);
    return output;
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PICTURE) {
      if (data != null) {
        if (data.hasExtra("data")) {
          b = data.getParcelableExtra("data");
        }
      } else {
        b = BitmapFactory.decodeFile(name);
      }
    } else if (requestCode == SELECT_PICTURE) {
      Uri selectedImage = data.getData();
      InputStream is;
      try {
        is = getContentResolver().openInputStream(selectedImage);
        BufferedInputStream bis = new BufferedInputStream(is);
        b = BitmapFactory.decodeStream(bis);

      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }
    try {
      // b = Bitmap.createScaledBitmap(b, 640, 480, true);
      bmini = Bitmap.createScaledBitmap(b, 64, 64, true);
      Toast.makeText(this, "Imagen Almacenada", Toast.LENGTH_SHORT).show();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #27
0
  private static Bitmap createVideoThumbnailBitmap(
      String filePath, FileDescriptor fd, int targetWidth) {
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
      if (filePath != null) {
        retriever.setDataSource(filePath);
      } else {
        retriever.setDataSource(fd);
      }
      bitmap = retriever.getFrameAtTime(-1);
    } catch (IllegalArgumentException ex) {
      // Assume this is a corrupt video file
    } catch (RuntimeException ex) {
      // Assume this is a corrupt video file.
    } finally {
      try {
        retriever.release();
      } catch (RuntimeException ex) {
        // Ignore failures while cleaning up.
      }
    }
    if (bitmap == null) return null;

    // Scale down the bitmap if it is bigger than we need.
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width > targetWidth) {
      float scale = (float) targetWidth / width;
      int w = Math.round(scale * width);
      int h = Math.round(scale * height);
      bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
    }
    return bitmap;
  }
  private void loadIdentity() {
    if (identitySelected.getProfileImage() != null) {
      Bitmap bitmap = null;
      if (identitySelected.getProfileImage().length > 0) {
        bitmap =
            BitmapFactory.decodeByteArray(
                identitySelected.getProfileImage(), 0, identitySelected.getProfileImage().length);
        //                bitmap = Bitmap.createScaledBitmap(bitmap, fanImage.getWidth(),
        // fanImage.getHeight(), true);
      } else {
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_profile_male);

        // Picasso.with(getActivity()).load(R.drawable.profile_image).into(fanImage);
      }
      bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
      fanImageByteArray = toByteArray(bitmap);
      fanImage.setImageDrawable(ImagesUtils.getRoundedBitmap(getResources(), bitmap));
    }
    mFanExternalUserName.setText(identitySelected.getUsername());
    //  mFanExternalPassword.setText(identitySelected.getApiToken());
    List<String> arraySpinner = ExternalPlatform.getArrayItems();
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arraySpinner);
    mFanExternalPlatform.setAdapter(adapter);
    ExternalPlatform[] externalPlatforms = ExternalPlatform.values();
    for (int i = 0; i < externalPlatforms.length; i++) {
      if (externalPlatforms[i] == identitySelected.getExternalPlatform()) {
        mFanExternalPlatform.setSelection(i);
        break;
      }
    }
  }
Example #29
0
  public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
      finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    else finalBitmap = bitmap;
    Bitmap output =
        Bitmap.createBitmap(
            finalBitmap.getWidth(), finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        finalBitmap.getWidth() / 2 + 0.7f,
        finalBitmap.getHeight() / 2 + 0.7f,
        finalBitmap.getWidth() / 2 + 0.1f,
        paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
  }
 private void refreshLoginState() {
   User userLoggedin = TavernaAndroid.getMyEUserLoggedin();
   String userName = null;
   if (userLoggedin != null) {
     userName = userLoggedin.getName();
     Bitmap avatarBitmap =
         TavernaAndroid.getmMemoryCache().get(userLoggedin.getAvatar().getResource());
     if (avatarBitmap != null) {
       // TODO : fixed scaled to 80 x 80
       Drawable avatarDrawable =
           new BitmapDrawable(
               getResources(), Bitmap.createScaledBitmap(avatarBitmap, 80, 80, false));
       /*Rect outRect = new Rect();
       myExperimentLoginText.getDrawingRect(outRect);
       // resize the Rect
       //outRect.inset(-10, 10);
       avatarDrawable.setBounds(outRect);
       myExperimentLoginText.setCompoundDrawables(avatarDrawable, null, null, null);*/
       myExperimentLoginText.setCompoundDrawablesWithIntrinsicBounds(
           avatarDrawable, null, null, null);
     }
     myExperimentLoginText.setText("Logged in as:\n" + userName);
   } else {
     Drawable defaultDrawable = getResources().getDrawable(R.drawable.myexperiment_logo_small);
     myExperimentLoginText.setCompoundDrawablesWithIntrinsicBounds(
         defaultDrawable, null, null, null);
     myExperimentLoginText.setText("Log in to myExperiment");
     myExperimentLoginText.setTextSize(15);
   }
 }