android图片圆角、图片去色处理示例

2019-12-10 20:04:48刘景俊

  * @return
  */
 private Bitmap createBitmap(Bitmap src, Bitmap watermark) {
  if (src == null) {
   return null;
  }
  int w = src.getWidth();
  int h = src.getHeight();
  int ww = watermark.getWidth();
  int wh = watermark.getHeight();
  // create the new blank bitmap
  Bitmap newb = Bitmap.createBitmap(w, h, Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
  Canvas cv = new Canvas(newb);
  // draw src into
  cv.drawBitmap(src, 0, 0, null);// 在 0,0坐标开始画入src
  // draw watermark into
  cv.drawBitmap(watermark, w - ww + 5, h - wh + 5, null);// 在src的右下角画入水印
  // save all clip
  cv.save(Canvas.ALL_SAVE_FLAG);// 保存
  // store
  cv.restore();// 存储
  return newb;
 }

 // 将图片转换成byte[]以便能将其存到数据库
 public static byte[] getByteFromBitmap(Bitmap bitmap) {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
  try {
   out.flush();
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
   // Log.e(TAG, "transform byte exception");
  }
  return out.toByteArray();
 }

 // 得到存储在数据库中的图片
 // eg imageView.setImageBitmap(bitmapobj);
 public static Bitmap getBitmapFromByte(byte[] temp) {
  if (temp != null) {
   Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
   return bitmap;
  } else {
   // Bitmap bitmap=BitmapFactory.decodeResource(getResources(),
   // R.drawable.contact_add_icon);
   return null;
  }
 }
    //将手机中的文件转换为Bitmap类型
 public static Bitmap getBitemapFromFile(File f) {
  if (!f.exists())
   return null;
  try {
   return BitmapFactory.decodeFile(f.getAbsolutePath());
  } catch (Exception ex) {
   return null;
  }
 }
 //将手机中的文件转换为Bitmap类型(重载+1)
 public static Bitmap getBitemapFromFile(String fileName) {