android 图片编辑时需要从外界(sdcard ,res/.png...,xml)读取图片到画布,其中从sdcard读取图片到画布的过程如下:
public void drawBitMapFromSDcard(String dir) {

if(dir ==null || dir.equals("")){
return ;
}
bitMap = BitmapFactory.decodeFile(dir);
int width = bitMap.getWidth();
int height = bitMap.getHeight();
如果图片像素太大超过手机屏幕大小可以按照手机屏比例进行缩放


if (width > 320 && height > 480) {
int newWidth = 320;
int newHeight = 480;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
float minScale = Math.min(scaleWidth, scaleHeight);
matrix = new Matrix();
matrix.postScale(minScale, minScale);
bitMap = Bitmap.createBitmap(bitMap, 0, 0, width, height,
matrix, true);
}
显示图片到手机屏幕
mCanvas.drawBitmap(bitMap, 0, 0, mPaint);
invalidate();





(二)图片剪切
在android 画布上对图像进行剪切时,首先选中一块区域,得到所选区域的像素点,然后放到到要粘贴的位置。剪切代码如下
public int[] getClipRectangePix(RectF rectf, Bitmap bitmap) {

int width = (int) rectf.width();
int height = (int) rectf.height();
int[] clipRectangePix = new int[(width * height)];// ????
int x = (int) rectf.left;
int y = (int) rectf.top;

bitmap.getPixels(clipRectangePix, 0, width, x, y, width, height);
// Log.v("pix Color:",""+ clipRectangePix[0] );
return clipRectangePix;

}








更多相关文章

  1. Android使用AsyncTask下载图片并显示进度条功能
  2. Android中屏幕密度和图片大小的关系分析
  3. MixtureTextView 支持Android图文混排、文字环绕图片等效果
  4. Android之UI学习篇七:ImageView实现适屏和裁剪图片的功能
  5. selector in Android
  6. (Android)处理图片成圆形
  7. Android(安卓)部分内容设置颜色、字体、超链接、图片
  8. android:scaleType设置失效的问题解决
  9. Android多点触控揭秘

随机推荐

  1. android 分享 api
  2. Android消息机制 Handler
  3. android 实现由下至上弹出并位于屏幕底部
  4. Android(安卓)GPS状态改变与监听
  5. android 设置静态wifi地址
  6. Android(安卓)软键盘小知识点
  7. android短信发送器源代码
  8. android 客户端 smtp 协议发送数据
  9. Working with Images in Google's Androi
  10. android FlexboxLayout可伸缩布局