一种是直接对Bitmap的像素进行操作,如:叠加、边框、怀旧、(高斯)模糊、锐化(拉普拉斯变换)。

Bitmap.getPixels(srcPixels, 0, width, 0, 0, width, height);

  newR = (int) (pixR * alpha + layR * (1 - alpha));
    newR = Math.min(255, Math.max(0, newR));
    。。。
    srcPixels[pos] = Color.argb(newA, newR, newG, newB);

Bitmap.setPixels(srcPixels, 0, width, 0, 0, width, height);

另一种是使用画布Canvas自带的函数进行处理,如:圆角、倒影、色相、饱和度、亮度、涂鸦:

Canvas canvas = new Canvas();//创建 空白画布,或new Canvas(bitmap)创建有背景画布,根据情况选择

Paint paint = new Paint();

。。。

canvas.drawBitmap(bitmap, null, rect, paint);

使用画布Canvas自带的函数进行处理的代码,以圆角特效为例:

  1. //圆角特效
  2. public static Bitmap getRoundCornerImage(Bitmap bitmap, int roundPixels, int width, int height )
  3. {
  4. //创建一个和原始图片一样大小位图
  5. Bitmap roundConcerImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);
  6. //创建带有位图roundConcerImage的画布
  7. Canvas canvas = new Canvas(roundConcerImage);
  8. //创建画笔
  9. Paint paint = new Paint();
  10. //创建一个和原始图片一样大小的矩形
  11. Rect rect = new Rect(0, 0, width, height);
  12. RectF rectF = new RectF(rect);
  13. // 去锯齿
  14. paint.setAntiAlias(true);
  15. //画一个和原始图片一样大小的圆角矩形
  16. canvas.drawRoundRect(rectF, roundPixels, roundPixels, paint);
  17. //设置相交模式
  18. paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  19. //把图片画到矩形去
  20. canvas.drawBitmap(bitmap, null, rect, paint);
  21. return roundConcerImage;
  22. }

直接对Bitmap的像素进行处理的代码,以怀旧特效为例:

  1. Handler handler = new Handler(){
  2.      @Override
  3.      public void handleMessage(Message msg) {
  4.        Drawable targetBitmapDrawable = new BitmapDrawable((Bitmap) msg.obj);// 将Bitmap转换为Drawable
  5.        is.setImageDrawable(targetBitmapDrawable);
  6.      }
  7.    };
  8.  
  9. /**
  10. * 怀旧效果
  11. * @param bmp
  12. * @return
  13. */
  14.    private void oldRemeber(final Bitmap bmp)
  15. {
  16.     Thread thread = new Thread() {
  17.     @Override
  18.     public void run() {
  19.  
  20. int width = bmp.getWidth();
  21. int height = bmp.getHeight();
  22. Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
  23. int pixColor = 0;
  24. int pixR = 0;
  25. int pixG = 0;
  26. int pixB = 0;
  27. int newR = 0;
  28. int newG = 0;
  29. int newB = 0;
  30. int[] pixels = new int[width * height];
  31. bmp.getPixels(pixels, 0, width, 0, 0, width, height);
  32. for (int i = 0; i < height; i++)
  33. {
  34. for (int k = 0; k < width; k++)
  35. {
  36. pixColor = pixels[width * i + k];
  37. pixR = Color.red(pixColor);
  38. pixG = Color.green(pixColor);
  39. pixB = Color.blue(pixColor);
  40. newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
  41. newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
  42. newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
  43. int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG, newB > 255 ? 255 : newB);
  44. pixels[width * i + k] = newColor;
  45. }
  46. }
  47. bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  48.  
  49.      Message message = handler.obtainMessage();
  50.      message.obj = bitmap;
  51.      handler.sendMessage(message);
  52.  
  53.     }
  54.  
  55.     };
  56.     thread.start();
  57.     thread = null;
  58. }

涂鸦特效再说明:

canvas = new Canvas(originalBitmap);//以原图片为背景创建画布

canvas.drawLine(startX, startY, clickX, clickY, paint);//根据手指移动画线条

canvas.drawBitmap(finalBitmap, 0, 0,null);//

左右旋转图片再说明:

  1. File MatrixLeftFile=new File(currentImagePath);
  2. try
  3. {
  4.   BitmapOrgLeft = BitmapFactory.decodeStream(new FileInputStream(MatrixLeftFile), null, RotateOptions);
  5. }
  6. catch (FileNotFoundException e2)
  7. {
  8.   // TODO 自动生成的 catch 块
  9.   e2.printStackTrace();
  10. }
  11. BitmapOrgLeft = Bitmap.createBitmap(BitmapOrgLeft, 0, 0, BitmapOrgLeft.getWidth(), BitmapOrgLeft.getHeight(), matrixleft, true);
  12. try
  13. {
  14.   bos = new BufferedOutputStream(new FileOutputStream(MatrixLeftFile));
  15. }
  16. catch (FileNotFoundException e1)
  17. {
  18.   // TODO 自动生成的 catch 块
  19.   e1.printStackTrace();
  20. }
  21. /* 采用压缩转档方法 */
  22. BitmapOrgLeft.compress(Bitmap.CompressFormat.JPEG, 100, bos);
  23. /* 调用flush()方法,更新BufferStream */
  24. try {
  25. bos.flush();
  26. } catch (IOException e) {
  27. // TODO 自动生成的 catch 块
  28. e.printStackTrace();
  29. }
  30. /* 结束OutputStream */
  31. try {
  32. bos.close();
  33. } catch (IOException e) {
  34. // TODO 自动生成的 catch 块
  35. e.printStackTrace();
  36. }
  37. imageAdapter.notifyDataSetChanged();
  38. //调用函数刷新图片
  39. Refresh_Rotating_Pictures();
  40. Toast.makeText(getBaseContext(), "保存成功!", Toast.LENGTH_LONG).show();
  41. //及时的释放 Bitmap 对象
  42. if(BitmapOrgLeft != null && !BitmapOrgLeft.isRecycled())
  43. {
  44. BitmapOrgLeft.recycle();
  45. BitmapOrgLeft = null;
  46. }

裁截图片再说明:

主要是两个函数和画布canvas的使用:

public void moveChooseArea(int move_x,int move_y){}:整体调整矩形的四条边,有最大最小限制。

private void pressLB(int x,int y)、 pressLT、 pressRB、 pressRT:调整相邻的某(左、上)两条边,有最大最小限制。

canvas.drawRect(ChooseArea, mPaint); 
        mPaint.setColor(Color.BLUE); 
        canvas.drawRect(recLT, mPaint); 
        canvas.drawRect(recLB, mPaint); 
        canvas.drawRect(recRT, mPaint);    
        canvas.drawRect(recRB, mPaint); 
         
        canvas.drawRect(leftRectL, leftAreaPaint); 
        canvas.drawRect(leftRectR, leftAreaPaint); 
        canvas.drawRect(leftRectT, leftAreaPaint); 
        canvas.drawRect(leftRectB, leftAreaPaint);

  1. package com.cutPicture;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Bitmap;
  5. import android.graphics.BitmapFactory;
  6. import android.graphics.Canvas;
  7. import android.graphics.Color;
  8. import android.graphics.Matrix;
  9. import android.graphics.Paint;
  10. import android.graphics.RectF;
  11. import android.graphics.Bitmap.Config;
  12. import android.graphics.drawable.BitmapDrawable;
  13. import android.util.AttributeSet;
  14. import android.view.MotionEvent;
  15. import android.widget.ImageView;
  16. //http://www.cdtarena.com/gpx/201305/8653.html
  17. public class MyCutView extends ImageView {
  18.  
  19. private final static int PRESS_LB = 0;//表示左下角矩形框
  20. private final static int PRESS_LT = 1;//表示左上角矩形框
  21. private final static int PRESS_RB = 2;//表示右下角矩形框
  22. private final static int PRESS_RT = 3;//表示右上角矩形框
  23.  
  24. private Bitmap bitMap = null; //原始图片
  25. private RectF src = null; //经过比例转换后的裁剪区域
  26. private RectF dst = null; //图片显示区域,也就是drawBitmap函数中的目标dst
  27. private RectF ChooseArea = null; //选择区域
  28. private Paint mPaint = null; //画笔
  29. private Matrix matrix = null; //矩阵
  30.  
  31. private int mx = 0; //存储触笔移动时,之前**的触笔的x坐标
  32. private int my = 0; //存储触笔移动时,之前**的触笔的y坐标
  33. private boolean touchFlag = false; //触笔是否在屏幕之*?
  34. private boolean cutFlag = false; //是否点击了menu上的裁剪按钮
  35. private int recFlag = -1; //用来存储触笔点击了哪个小矩形框(改变选择区域大小的小矩形框)
  36. private boolean firstFlag = false;
  37.  
  38. private RectF recLT = null; //左上角的小矩形框
  39. private RectF recRT = null; //右上角的小矩形框
  40. private RectF recLB = null; //左下角的小矩形框
  41. private RectF recRB = null; //右下角的小矩形框
  42. private static final int LEFT_AREA_ALPHA = 50 * 255 / 100;
  43. private RectF leftRectL = null;
  44. private RectF leftRectR = null;
  45. private RectF leftRectT = null;
  46. private RectF leftRectB = null;
  47. private Paint leftAreaPaint = null;
  48.  
  49. int padding=0;
  50.  
  51. public String editImagePath=null;
  52. public MyCutView(Context context, AttributeSet attrs) {
  53. super(context, attrs);
  54. this.init();
  55. }
  56.  
  57. public MyCutView(Context context) {
  58. super(context);
  59. this.init();
  60. }
  61.  
  62. public void init(){
  63. cutFlag = true;
  64. recLT = new RectF();
  65. recLB = new RectF();
  66. recRT = new RectF();
  67. recRB = new RectF();
  68. dst = new RectF();
  69. mPaint = new Paint();
  70. mPaint.setColor(Color.RED);
  71. mPaint.setStyle(Paint.Style.STROKE); //将画笔的风格改为空心
  72. ChooseArea = new RectF();
  73. this.setPressRecLoc();
  74. src = null;
  75. firstFlag = true;
  76.  
  77. //选择框之外的灰色区域,分成四个矩形框
  78.  
  79. leftAreaPaint = new Paint();
  80. leftAreaPaint.setStyle(Paint.Style.FILL);
  81. leftAreaPaint.setAlpha(MyCutView.LEFT_AREA_ALPHA);
  82. }
  83.  
  84. public void setBitmap(Bitmap bitmap){
  85. BitmapDrawable bd = new BitmapDrawable(bitmap);
  86. src = new RectF(0,0,bd.getIntrinsicWidth(),bd.getIntrinsicHeight());
  87. this.bitMap = bitmap.copy(Config.ARGB_8888, true);
  88.  
  89. this.setImageBitmap(bitMap);
  90. leftRectB = new RectF();
  91. leftRectL = new RectF();
  92. leftRectR = new RectF();
  93. leftRectT = new RectF();
  94. }
  95.  
  96. public void imageScale(){
  97. matrix = this.getImageMatrix();
  98. matrix.mapRect(dst, src);
  99. padding = this.getPaddingBottom();
  100. /*
  101. int width = bitMap.getWidth();
  102. int height = bitMap.getHeight();
  103. //dst.set(dst.left+padding,dst.top+padding,dst.right+padding,dst.bottom+padding);
  104. if(height>width)
  105. {
  106. dst.set(dst.left,dst.top,width-7,height+100); 适用于android:layout_width="wrap_content"是FillParent并且没有android:layout_centerInParent="true"属性
  107. }
  108. else
  109. {
  110. dst.set(dst.left,dst.top,width-170,height+120);
  111. }
  112. */
  113. int w=this.getWidth();
  114. int h=this.getHeight();
  115. //if(h>w)
  116. {
  117. dst.set(dst.left+2,dst.top+2,w-4,h-6);
  118. }
  119. //else
  120. if(editImagePath!=null)
  121. {
  122. BitmapFactory.Options options = new BitmapFactory.Options();
  123. options.inJustDecodeBounds = true;
  124. BitmapFactory.decodeFile(editImagePath, options);
  125. int tempH = options.outHeight;
  126. if(tempH==1944)
  127. {
  128. dst.set(dst.left+2,dst.top+2,w-4,h-67);
  129. }
  130. }
  131. ChooseArea = new RectF(dst);
  132. this.setPressRecLoc();
  133. }
  134.  
  135. public Bitmap getSubsetBitmap(){
  136. float ratioWidth = bitMap.getWidth()/(float)(dst.right-dst.left);
  137. float ratioHeight = bitMap.getHeight()/(float)(dst.bottom - dst.top);
  138. int left = (int)((ChooseArea.left - dst.left) * ratioWidth);
  139. int right = (int)(left + (ChooseArea.right - ChooseArea.left) * ratioWidth);
  140. int top = (int)((ChooseArea.top - dst.top) * ratioHeight);
  141. int bottom = (int)(top + (ChooseArea.bottom - ChooseArea.top) * ratioHeight);
  142. src = new RectF(left,top,right,bottom);
  143. firstFlag = true;
  144. set_LeftArea_Alpha();
  145. return Bitmap.createBitmap(bitMap, left, top, right-left, bottom-top);
  146. }
  147.  
  148. //获得ChooseArea对象
  149. public RectF getChooseArea(){
  150. return ChooseArea;
  151. }
  152.  
  153. public void moveChooseArea(int move_x,int move_y){
  154. if(ChooseArea.left + move_x >= dst.left && ChooseArea.right + move_x <= dst.right
  155. && ChooseArea.top + move_y >= dst.top && ChooseArea.bottom + move_y <= dst.bottom){
  156. ChooseArea.set(ChooseArea.left + move_x,ChooseArea.top+move_y
  157. ,ChooseArea.right + move_x,ChooseArea.bottom+move_y);
  158. }else{
  159. if(ChooseArea.left + move_x < dst.left){
  160. ChooseArea.set(dst.left,ChooseArea.top
  161. ,ChooseArea.right+dst.left-ChooseArea.left,ChooseArea.bottom);
  162. }
  163. if(ChooseArea.right + move_x > dst.right){
  164. ChooseArea.set(ChooseArea.left+dst.right-ChooseArea.right,ChooseArea.top
  165. ,dst.right,ChooseArea.bottom);
  166. }
  167.  
  168. if(ChooseArea.top + move_y < dst.top){
  169. ChooseArea.set(ChooseArea.left,dst.top
  170. ,ChooseArea.right,ChooseArea.bottom+dst.top-ChooseArea.top);
  171. }
  172.  
  173. if(ChooseArea.bottom + move_y > dst.bottom){
  174. ChooseArea.set(ChooseArea.left,ChooseArea.top+dst.bottom-ChooseArea.bottom
  175. ,ChooseArea.right,dst.bottom);
  176. }
  177. }
  178. this.setPressRecLoc();
  179. mPaint.setColor(Color.GREEN);
  180. this.invalidate();
  181. }
  182.  
  183. public boolean onTouchEvent(MotionEvent event){
  184. mPaint.setColor(Color.RED);
  185.  
  186. if(event.getAction() == MotionEvent.ACTION_DOWN && cutFlag){
  187. //System.out.println(event.getX() + "," + event.getY());
  188.  
  189. mx = (int)event.getX();
  190. my = (int)event.getY();
  191. if(this.judgeLocation(mx,my)){
  192. touchFlag = true;
  193. mPaint.setColor(Color.GREEN);
  194. this.invalidate();
  195. return true;
  196. }else{
  197.  
  198. if(this.findPresseddst((int)event.getX(), (int)event.getY())){
  199. touchFlag = true;
  200. mPaint.setColor(Color.RED);
  201. return true;
  202. }
  203. }
  204. }
  205.  
  206. if(event.getAction() == MotionEvent.ACTION_MOVE && touchFlag){
  207. //判断是否点击了哪个个小矩形框
  208. if(this.isOutOfArea((int)event.getX(), (int)event.getY())){
  209. return true;
  210. }
  211.  
  212. //www.cdtarena.com如果选择区域大小跟图像大小一样时,就不能移动
  213. if(ChooseArea.left == dst.left && ChooseArea.top == dst.top &&
  214. ChooseArea.right == dst.right && ChooseArea.bottom == dst.bottom){
  215. }else{
  216. this.moveChooseArea((int)event.getX() - mx, (int)event.getY() - my);
  217. mx = (int)event.getX();
  218. my = (int)event.getY();
  219. }
  220. }
  221.  
  222. if(event.getAction() == MotionEvent.ACTION_UP){
  223. recFlag = -1;
  224. this.invalidate();
  225. touchFlag = false;
  226. }
  227.  
  228. return super.onTouchEvent(event);
  229. }
  230.  
  231. private boolean isOutOfArea(int x,int y){
  232. switch(recFlag){
  233. case MyCutView.PRESS_LB:
  234. this.pressLB(x - mx, y - my);
  235. break;
  236. case MyCutView.PRESS_LT:
  237. this.pressLT(x - mx, y - my);
  238. break;
  239. case MyCutView.PRESS_RB:
  240. this.pressRB(x - mx, y - my);
  241. break;
  242. case MyCutView.PRESS_RT:
  243. this.pressRT(x - mx, y - my);
  244. break;
  245. default:return false;
  246. }
  247. mx = x;
  248. my = y;
  249. this.invalidate();
  250. return true;
  251. }
  252.  
  253. public boolean findPresseddst(int x,int y){
  254. boolean returnFlag = false;
  255. if(this.isInRect(x, y, recLB)){
  256. recFlag = MyCutView.PRESS_LB;
  257. returnFlag = true;
  258. }else if(this.isInRect(x, y, recLT)){
  259. recFlag = MyCutView.PRESS_LT;
  260. returnFlag = true;
  261. }else if(this.isInRect(x, y, recRB)){
  262. recFlag = MyCutView.PRESS_RB;
  263. returnFlag = true;
  264. }else if(this.isInRect(x, y, recRT)){
  265. recFlag = MyCutView.PRESS_RT;
  266. returnFlag = true;
  267. }
  268.  
  269. return returnFlag;
  270. }
  271.  
  272. public boolean isInRect(int x,int y,RectF rect){
  273. if(x >= rect.left -20 && x <= rect.right + 20 && y > rect.top - 20 && y < rect.bottom + 20){
  274. return true;
  275. }
  276. return false;
  277. }
  278.  
  279. private void pressLB(int x,int y){
  280. float left = ChooseArea.left + x;
  281. float right = ChooseArea.right;
  282. float top = ChooseArea.top;
  283. float bottom = ChooseArea.bottom + y;
  284. if(left <= right - 30 && left >= dst.left && bottom <= dst.bottom && bottom >= top + 30){
  285. ChooseArea.set(left,top,right,bottom);
  286. }else{
  287. if(left + x < dst.left){
  288. left = dst.left;
  289. }
  290.  
  291. if(bottom + y > dst.bottom){
  292. bottom = dst.bottom;
  293. }
  294.  
  295. if(ChooseArea.left + x > ChooseArea.right - 30){
  296. left = ChooseArea.right - 30;
  297. }
  298.  
  299. if(ChooseArea.bottom + y < ChooseArea.top + 30){
  300. bottom = ChooseArea.top + 30;
  301. }
  302. ChooseArea.set(left,top,right,bottom);
  303. }
  304. this.setPressRecLoc();
  305. }
  306.  
  307. private void pressLT(int x,int y){
  308. float left = ChooseArea.left + x;
  309. float right = ChooseArea.right;
  310. float top = ChooseArea.top + y;
  311. float bottom = ChooseArea.bottom;
  312. if(left <= right - 30 && left >= dst.left && top <= bottom - 30 && top >= dst.top){
  313. ChooseArea.set(left,top,right,bottom);
  314. }else{
  315. if(left < dst.left){
  316. left = dst.left;
  317. }
  318.  
  319. if(top < dst.top){
  320. top = dst.top;
  321. }
  322.  
  323. if(left > right - 30){
  324. left = right - 30;
  325. }
  326.  
  327. if(top > bottom - 30){
  328. top = bottom - 30;
  329. }
  330. ChooseArea.set(left,top,right,bottom);
  331. }
  332. this.setPressRecLoc();
  333. }
  334.  
  335. private void pressRT(int x,int y){
  336. float left = ChooseArea.left;
  337. float right = ChooseArea.right + x;
  338. float top = ChooseArea.top + y;
  339. float bottom = ChooseArea.bottom;
  340.  
  341. if(right <= dst.right && right >= left + 30 && top <= bottom - 30 && top >= dst.top){
  342. ChooseArea.set(left,top,right,bottom);
  343. }else{
  344. if(right > dst.right){
  345. right = dst.right;
  346. }
  347.  
  348. if(top < dst.top){
  349. top = dst.top;
  350. }
  351.  
  352. if(right < left + 30){
  353. right = left + 30;
  354. }
  355.  
  356. if(top > bottom - 30){
  357. top = bottom - 30;
  358. }
  359. ChooseArea.set(left,top,right,bottom);
  360. }
  361. this.setPressRecLoc();
  362. }
  363.  
  364. private void pressRB(int x,int y){
  365. float left = ChooseArea.left;
  366. float right = ChooseArea.right + x;
  367. float top = ChooseArea.top;
  368. float bottom = ChooseArea.bottom + y;
  369.  
  370. if(right<= dst.right && right >= left + 30 && bottom <= dst.bottom && bottom >= top + 30){
  371. ChooseArea.set(left,top,right,bottom);
  372. }else{
  373. if(right > dst.right){
  374. right = dst.right;
  375. }
  376.  
  377. if(bottom > dst.bottom){
  378. bottom = dst.bottom;
  379. }
  380.  
  381. if(right < left + 30){
  382. right = left + 30;
  383. }
  384.  
  385. if(bottom < top + 30){
  386. bottom = top + 30;
  387. }
  388. ChooseArea.set(left,top,right,bottom);
  389. }
  390. this.setPressRecLoc();
  391. }
  392.  
  393. //每次改变选择区域矩形的大小或者移动,各角落上的小矩形也要改变它的Location
  394. private void setPressRecLoc(){
  395. recLT.set(ChooseArea.left-5,ChooseArea.top-5 , ChooseArea.left+5, ChooseArea.top+5);
  396. recLB.set(ChooseArea.left-5,ChooseArea.bottom-5 , ChooseArea.left+5, ChooseArea.bottom+5);
  397. recRT.set(ChooseArea.right-5,ChooseArea.top-5 , ChooseArea.right+5, ChooseArea.top+5);
  398. recRB.set(ChooseArea.right-5,ChooseArea.bottom-5 , ChooseArea.right+5, ChooseArea.bottom+5);
  399. }
  400.  
  401. public boolean judgeLocation(float x,float y){
  402. float start_x = this.getChooseArea().left;
  403. float start_y = this.getChooseArea().top;
  404. float last_x = this.getChooseArea().right;
  405. float last_y = this.getChooseArea().bottom;
  406. //System.out.println("chubi:" + x + "," + y);
  407. //System.out.println(start_y + "," + last_y);
  408. if(x > start_x+10 && x < last_x-10 && y > start_y+10 && y < last_y-10){
  409. return true;
  410. }
  411. return false;
  412. }
  413.  
  414. public void onDraw(Canvas canvas){
  415. super.onDraw(canvas);
  416. if(firstFlag){
  417. this.imageScale();
  418. firstFlag = false;
  419. mPaint.setColor(Color.RED);
  420. System.out.println("Width: " + (dst.right - dst.left));
  421. System.out.println("Height: " + (dst.bottom - dst.top));
  422. System.out.println("Width: " + this.getDrawable().getIntrinsicWidth());
  423. System.out.println("Height: " + this.getDrawable().getIntrinsicHeight());
  424. }else{
  425. set_LeftArea_Alpha();
  426. }
  427. canvas.drawRect(ChooseArea, mPaint);
  428. mPaint.setColor(Color.BLUE);
  429. canvas.drawRect(recLT, mPaint);
  430. canvas.drawRect(recLB, mPaint);
  431. canvas.drawRect(recRT, mPaint);
  432. canvas.drawRect(recRB, mPaint);
  433.  
  434. canvas.drawRect(leftRectL, leftAreaPaint);
  435. canvas.drawRect(leftRectR, leftAreaPaint);
  436. canvas.drawRect(leftRectT, leftAreaPaint);
  437. canvas.drawRect(leftRectB, leftAreaPaint);
  438.  
  439. }
  440.  
  441. public void set_LeftArea_Alpha(){
  442. leftRectL.set(dst.left, dst.top, ChooseArea.left, dst.bottom);
  443. leftRectR.set(ChooseArea.right,dst.top,dst.right,dst.bottom);
  444. leftRectT.set(ChooseArea.left, dst.top, ChooseArea.right, ChooseArea.top);
  445. leftRectB.set(ChooseArea.left,ChooseArea.bottom,ChooseArea.right,dst.bottom);
  446. }
  447. }

播放幻灯片浏览图片再说明:

使用两个全局变量:

public String[] myImageNames;   //所有的图片的名字

public int ImageNameId = 0;     //图片编号

public String picfolderPath;    //实际上是 文件夹 的路径

开个线程,每3秒显示一张图片:

ImagePath = picfolderPath + File.separator + myImageNames[ImageNameId];

ImageNameId++;

  1. public String picfolderPath; //实际上是 文件夹 的路径
  2. public String[] myImageNames; //所有的图片的名字
  3. public int ImageNameId = 0; //图片编号
  4. public String ImagePath ; //图片的路径
  5.  
  6. is = (ImageSwitcher) findViewById(R.id.slideshow_switcher);
  7. is.setFactory(this);
  8. is.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
  9. is.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
  10.  
  11. Runnable runnable=new Runnable() { //采用Handler的postDelayed(Runnable, long)方法 计时
  12. @Override
  13. public void run() {
  14. // TODO Auto-generated method stub
  15. if(ImageNameId < myImageNames.length)
  16. {
  17. is.reset();
  18. ImagePath = picfolderPath + File.separator + myImageNames[ImageNameId];
  19. ImageNameId++;
  20. getSampledBitmap(ImagePath);
  21. }
  22. else if(ImageNameId ==myImageNames.length)
  23. {
  24. is.reset();
  25. ImageNameId = 0; //重置 ImageNameId,实现循环播放
  26. ImagePath = picfolderPath + File.separator + myImageNames[ImageNameId];
  27. ImageNameId++;
  28. getSampledBitmap(ImagePath);
  29. }
  30. //handler.removeCallbacks(runnable);//停止计时器
  31. //handler.postDelayed(this, 3000);//3秒时间间隔
  32.   }
  33. };

Camera图片特效处理综述(Bitmap的Pixels处理、Canvas/paint的drawBitmap处理、旋转图片、裁截图片、播放幻灯片浏览图片<线程固定时间显示一张>)的更多相关文章

  1. android图片特效处理之模糊效果

    这篇将讲到图片特效处理的模糊效果.跟前面一样是对像素点进行处理,算法是通用的,但耗时会更长,至于为什么,看了下面的代码你就会明白. 算法: 一.简单算法:将像素点周围八个点包括自身一共九个点的RGB值 ...

  2. android 图片特效处理之 光晕效果

    这篇将讲到图片特效处理的图片光晕效果.跟前面一样是对像素点进行处理,本篇实现的思路可参见android图像处理系列之九--图片特效处理之二-模糊效果和android图像处理系列之十三--图片特效处理之 ...

  3. android 图片特效处理之光晕效果

    这篇将讲到图片特效处理的图片光晕效果.跟前面一样是对像素点进行处理,本篇实现的思路可参见android图像处理系列之九--图片特效处理之二-模糊效果和android图像处理系列之十三--图片特效处理之 ...

  4. android 图片特效处理之锐化效果

    这篇将讲到图片特效处理的锐化效果.跟前面一样是对像素点进行处理,算法是通用的. 算法原理: 一.简单算法:分别获取当前像素点和八个周围像素点的RGB值,先求出当前像素点的RGB值与八个像素点RGB值的 ...

  5. android 图片特效处理之模糊效果

    这篇将讲到图片特效处理的模糊效果.跟前面一样是对像素点进行处理,算法是通用的,但耗时会更长,至于为什么,看了下面的代码你就会明白. 算法: 一.简单算法:将像素点周围八个点包括自身一共九个点的RGB值 ...

  6. android 图片特效处理之怀旧效果

    图片特效处理系列将介绍图片的像素点的特效处理,这些物资注重的是原理.也就是说只要你知道这些算法不管是C++,VB,C#,Java都可以做出相同的特效.下面将介绍图片怀旧效果的算法.算法如下: 上面公式 ...

  7. android图片特效处理之怀旧效果

    图片特效处理系列将介绍图片的像素点的特效处理,这些物资注重的是原理.也就是说只要你知道这些算法不管是C++,VB,C#,Java都可以做出相同的特效.下面将介绍图片怀旧效果的算法.算法如下: 上面公式 ...

  8. android图片特效处理之锐化效果

    这篇将讲到图片特效处理的锐化效果.跟前面一样是对像素点进行处理,算法是通用的. 算法原理: 一.简单算法:分别获取当前像素点和八个周围像素点的RGB值,先求出当前像素点的RGB值与八个像素点RGB值的 ...

  9. android图片特效处理之光晕效果

    这篇将讲到图片特效处理的图片光晕效果.跟前面一样是对像素点进行处理,本篇实现的思路可参见android图像处理系列之九--图片特效处理之二-模糊效果和android图像处理系列之十三--图片特效处理之 ...

随机推荐

  1. VC程序查错之内存访问异常

    作者:langouster 先来看下面这张图,相信很多程序员都见过类似. ---------------------------test1.exe - 应用程序错误------------------ ...

  2. JavaScript DOM编程基础精华03(动态设置,层的操作,性能问题)

    代码是否需要放置到onload中  //如果js代码需要操作页面上的元素,则将该代码放到onload里面.         //因为当页面加载完毕之后页面上才会有相关的元素 //如果js代码中没有操作 ...

  3. ORA-12571 : TNS : 包写入程序失败

    错误原因 解决方案 修改D:/oracle/ora92/network/admin目录下sqlnet.ora,将”NAMES.DEFAULT_DOMAIN =” 这一行用#注释掉,将“SQLNET.A ...

  4. C++:运算符重载函数

    5.运算符重载 5.1 在类外定义的运算符重载函数 C++为运算符重载提供了一种方法,即在运行运算符重载时,必须定义一个运算符重载函数,其名字为operator,后随一个要重载的运算符.例如,要重载& ...

  5. Splunk作为日志分析平台与Ossec进行联动

    背景: Ossec安装后用了一段时间的analogi作为ossec的报警信息显示平台,但是查看报警分类信息. 以及相关图标展示等方面总有那么一点点的差强人意,难以分析.因此使用逼格高一点的splunk ...

  6. 4、JPA table主键生成策略(在JPA中table策略是首推!!!)

    用 table 来生成主键详解 它是在不影响性能情况下,通用性最强的 JPA 主键生成器.这种方法生成主键的策略可以适用于任何数据库,不必担心不同数据库不兼容造成的问题. initialValue不起 ...

  7. (四)CSS选择器和派生选择器

    CSS派生选择器允许你根据文档的上下文关系来确定某个标签的样式.在学习派生之前,先来了解基本的CSS选择器.前面的文章中提到过下图,选择器的位置如下所示: CSS选择器 分为几种基本选择器:元素选择器 ...

  8. java导出excel报表

    1.java导出excel报表: package cn.jcenterhome.util; import java.io.OutputStream;import java.util.List;impo ...

  9. Bug:java.lang.IllegalStateException

    使用迭代的时候,出现了java.lang.IllegalStateException 代码: for ( TaskInfo info : userTaskInfos ) { if ( info.isC ...

  10. Oracle学习之集合运算

    一.集合运算操作符  UNION:(并集)返回两个集合去掉重复值的所有的记录  UNION ALL:(并集)返回两个集合去掉重复值的所有的记录 INTERSECT:(交集)返回两个集合的所有记录,重复 ...