Android Open Source - Ocypode Bitmap Util






From Project

Back to project page Ocypode.

License

The source code is released under:

MIT License

If you think the Android project Ocypode listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ocypode.utility.bitmap;
/* www.j  av  a2 s.  co  m*/
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.os.Build;

public class BitmapUtil {

  public static Bitmap downSizeBitmap(Bitmap bitmap,int reqSize)  {
    
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
     
    float scaleWidth = ((float) reqSize) / width;
    float scaleHeight = ((float) reqSize) / height;
     
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
     
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
    return resizedBitmap;
     
    /*if(bitmap.getWidth() < reqSize) {
      return bitmap;
    } else {
      return Bitmap.createScaledBitmap(bitmap, reqSize, reqSize, false);
    } */
  }
  
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public static byte[] convertBitmapToBytes(Bitmap bitmap) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
          bitmap.copyPixelsToBuffer(buffer);
          return buffer.array();
      } else {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();  
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
          byte[] data = baos.toByteArray();
          return data;
      }
    }

}




Java Source Code List

com.ocypode.BuildConfig.java
com.ocypode.BuildConfig.java
com.ocypode.activity.IResultCallbackActivity.java
com.ocypode.activity.robo.AbstractRoboActivity.java
com.ocypode.activity.robo.AbstractRoboFragmentActivity.java
com.ocypode.activity.robo.fragment.AbstractRoboFragment.java
com.ocypode.bluetooth.BluetoothHelper.java
com.ocypode.component.Typefaced.java
com.ocypode.component.animation.AnimationCallbackListener.java
com.ocypode.component.delegate.IStartActivityDelegate.java
com.ocypode.component.delegate.StartActivityDelegate.java
com.ocypode.component.delegate.adaptor.IStartActivityAdaptor.java
com.ocypode.component.delegate.adaptor.StartActivityAdaptor.java
com.ocypode.component.delegate.adaptor.StartFragmentAdaptor.java
com.ocypode.component.view.button.TypefacedButton.java
com.ocypode.component.view.dialog.AlertDialogBuilder.java
com.ocypode.component.view.dialog.ProgressDialogBuilder.java
com.ocypode.component.view.dialog.titledescription.TitleDescriptionArrayAdapter.java
com.ocypode.component.view.dialog.titledescription.TitleDescriptionModel.java
com.ocypode.component.view.edittext.TypefacedEditText.java
com.ocypode.component.view.imageview.CircleImageView.java
com.ocypode.component.view.listview.LockableListView.java
com.ocypode.component.view.scrollview.LockableScrollView.java
com.ocypode.component.view.textview.AutoResizeTextView.java
com.ocypode.component.view.textview.TypefacedTextView.java
com.ocypode.repository.AbstractRepository.java
com.ocypode.utility.ICallback.java
com.ocypode.utility.Logcat.java
com.ocypode.utility.Utility.java
com.ocypode.utility.bitmap.BitmapUtil.java
com.ocypode.utility.formatter.CurrencyFormatter.java
com.ocypode.utility.formatter.DateFormatter.java
com.ocypode.utility.formatter.NumberFormatter.java
com.ocypode.utility.validation.StringValidation.java
com.ocypode.widgets.list.OCListView.java