Android 图片处理工具类汇总
很有用的Android图片处理工具,实现各种图片处理效果
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
/*******图片加载与保存*******/
/** * 以最省内存的方式读取本地资源的图片 * * @param context * @param resId * @return */ public Bitmap readBitMap(int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; // 获取资源图片 InputStream is = getResources().openRawResource(resId); return BitmapFactory.decodeStream(is, null, opt); } /** //保存图片到本地路径 // 从view得到bitmap /** /** /*******获取图片信息*******/ /** /*******图片转换*******/ private byte[] Bitmap2Bytes(Bitmap bm) { private Bitmap Bytes2Bimap(byte[] b) { //Stream转换成Byte } /** Bitmap 格式转换 byte[] array = os.toByteArray(); /*******图片缩放剪裁和形变*******/ /** /** //放大缩小图片,生成缩略图 /** /*** public final void cuteImage(Canvas g, Paint paint, Bitmap imgBit, int x, //将一个图片切割成多个图片 public static List<ImagePiece> split(Bitmap bitmap, int xPiece, int yPiece) { List<ImagePiece> pieces = new ArrayList<ImagePiece>(xPiece * yPiece); return pieces; } //图片翻转 /** /*******图片效果处理*******/ /** public class ImgService { /** Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, // Bitmap加水印 int sWid = src.getWidth(); if (sWid < wWid || sHei < wHei) { Bitmap bitmap = Bitmap.createBitmap(sWid, sHei, Config.ARGB_8888);//Config可修改,改变内存占用 /** return output; /*** } //获得带倒影的图片方法 Matrix matrix = new Matrix(); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); return bitmapWithReflection; //Android Matrix类实现镜像倒影方法 int x_src, int y_src, int width, int height, int transform, int x_dest, int y_dest, int anchor) { if((anchor & VCENTER) != 0) { y_dest -= height / 2; } else if((anchor & BOTTOM) != 0) { y_dest -= height; } if((anchor & RIGHT) != 0) { x_dest -= width; } else if((anchor & HCENTER) != 0) { x_dest -= width / 2; } Bitmap newMap = Bitmap.createBitmap(image_src.getBitmap(), x_src, y_src, width, height); Matrix mMatrix = new Matrix(); Matrix temp = new Matrix(); Matrix temp2 = new Matrix(); float[] mirrorY = { -1, 0, 0, }; temp.setValues(mirrorY); switch(transform) { case Sprite.TRANS_NONE: break; case Sprite.TRANS_ROT90: mMatrix.setRotate(90, width / 2, height / 2); break; case Sprite.TRANS_ROT180: mMatrix.setRotate(180, width / 2, height / 2); break; case Sprite.TRANS_ROT270: mMatrix.setRotate(270, width / 2, height / 2); break; case Sprite.TRANS_MIRROR: mMatrix.postConcat(temp); break; case Sprite.TRANS_MIRROR_ROT90: mMatrix.postConcat(temp); mMatrix.setRotate(90, width / 2, height / 2); break; case Sprite.TRANS_MIRROR_ROT180: mMatrix.postConcat(temp); mMatrix.setRotate(180, width / 2, height / 2); break; case Sprite.TRANS_MIRROR_ROT270: mMatrix.postConcat(temp); mMatrix.setRotate(270, width / 2, height / 2); break; } mMatrix.setTranslate(x_dest, y_dest); canvas.drawBitmap(newMap, mMatrix, mPaint); } /** int []pixels = new int[width * height]; //通过位图的大小创建像素点数组 img.getPixels(pixels, 0, width, 0, 0, width, height); int red = ((grey & 0x00FF0000 ) >> 16); grey = (int)((float) red * 0.3 + (float)green * 0.59 + (float)blue * 0.11); //压缩图片大小 ByteArrayOutputStream baos = new ByteArrayOutputStream(); //同一张图片在两个不同的地方用到,但是两处的效果不一样。 |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
/*******图片加载与保存*******/
/** * 以最省内存的方式读取本地资源的图片 * * @param context * @param resId * @return */ public Bitmap readBitMap(int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; // 获取资源图片 InputStream is = getResources().openRawResource(resId); return BitmapFactory.decodeStream(is, null, opt); } /** //保存图片到本地路径 // 从view得到bitmap /** /** /*******获取图片信息*******/ /** /*******图片转换*******/ private byte[] Bitmap2Bytes(Bitmap bm) { private Bitmap Bytes2Bimap(byte[] b) { //Stream转换成Byte } /** Bitmap 格式转换 byte[] array = os.toByteArray(); /*******图片缩放剪裁和形变*******/ /** /** //放大缩小图片,生成缩略图 /** /*** public final void cuteImage(Canvas g, Paint paint, Bitmap imgBit, int x, //将一个图片切割成多个图片 public static List<ImagePiece> split(Bitmap bitmap, int xPiece, int yPiece) { List<ImagePiece> pieces = new ArrayList<ImagePiece>(xPiece * yPiece); return pieces; } //图片翻转 /** /*******图片效果处理*******/ /** public class ImgService { /** Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, // Bitmap加水印 int sWid = src.getWidth(); if (sWid < wWid || sHei < wHei) { Bitmap bitmap = Bitmap.createBitmap(sWid, sHei, Config.ARGB_8888);//Config可修改,改变内存占用 /** return output; /*** } //获得带倒影的图片方法 Matrix matrix = new Matrix(); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); return bitmapWithReflection; //Android Matrix类实现镜像倒影方法 int x_src, int y_src, int width, int height, int transform, int x_dest, int y_dest, int anchor) { if((anchor & VCENTER) != 0) { y_dest -= height / 2; } else if((anchor & BOTTOM) != 0) { y_dest -= height; } if((anchor & RIGHT) != 0) { x_dest -= width; } else if((anchor & HCENTER) != 0) { x_dest -= width / 2; } Bitmap newMap = Bitmap.createBitmap(image_src.getBitmap(), x_src, y_src, width, height); Matrix mMatrix = new Matrix(); Matrix temp = new Matrix(); Matrix temp2 = new Matrix(); float[] mirrorY = { -1, 0, 0, }; temp.setValues(mirrorY); switch(transform) { case Sprite.TRANS_NONE: break; case Sprite.TRANS_ROT90: mMatrix.setRotate(90, width / 2, height / 2); break; case Sprite.TRANS_ROT180: mMatrix.setRotate(180, width / 2, height / 2); break; case Sprite.TRANS_ROT270: mMatrix.setRotate(270, width / 2, height / 2); break; case Sprite.TRANS_MIRROR: mMatrix.postConcat(temp); break; case Sprite.TRANS_MIRROR_ROT90: mMatrix.postConcat(temp); mMatrix.setRotate(90, width / 2, height / 2); break; case Sprite.TRANS_MIRROR_ROT180: mMatrix.postConcat(temp); mMatrix.setRotate(180, width / 2, height / 2); break; case Sprite.TRANS_MIRROR_ROT270: mMatrix.postConcat(temp); mMatrix.setRotate(270, width / 2, height / 2); break; } mMatrix.setTranslate(x_dest, y_dest); canvas.drawBitmap(newMap, mMatrix, mPaint); } /** int []pixels = new int[width * height]; //通过位图的大小创建像素点数组 img.getPixels(pixels, 0, width, 0, 0, width, height); int red = ((grey & 0x00FF0000 ) >> 16); grey = (int)((float) red * 0.3 + (float)green * 0.59 + (float)blue * 0.11); //压缩图片大小 ByteArrayOutputStream baos = new ByteArrayOutputStream(); //同一张图片在两个不同的地方用到,但是两处的效果不一样。 |
Android 图片处理工具类汇总相关推荐
- Android 图片处理工具类封装2
http://www.2cto.com/kf/201312/263638.html Android 图片处理工具类封装 2013-12-10 0个评论 来源:Wiker Yong 的专栏 ...
- android 图片缓存工具类,Android工具类系列-Glide图片缓存与圆角
Glide的图片缓存和清除图片缓存 public class GlideCacheUtil { private static GlideCacheUtil inst; public static Gl ...
- Android常用的工具类汇总(方便日后使用)
平时进行android开发时候,可能需要使用各种各样的工具类,每次总要去上网搜索,费时费力,因此特此将其整理发出来,小伙伴可自行收藏. 1.LogUtils工具类 /*** 控制Log开关的工具类*/ ...
- android图片下载工具类
public class HttpRequestImage {public static String headpath="/sdcard/head/";//图片保存地址 // p ...
- Android 图片下载工具类
public class DownGoodsImage {private Context context;private String filePath;private String fileName ...
- ImageView可直接调用的,根据URL设置图片的工具类
ImageView 是Android编程中最常用的组件之一. 但是根据图片的URL设置图片却很麻烦.因为获取网络图片的操作必须在异步线程中进行,根据URL设置ImageView图片就可能需要进行线程间 ...
- Android常用的工具类
2019独角兽企业重金招聘Python工程师标准>>> 最新最准确内容建议直接访问原文:Android常用的工具类 主要介绍总结的Android开发中常用的工具类,大部分同样适用于J ...
- Android开发常用工具类集合
转载自:https://blog.csdn.net/xiaoyi_tdcq/article/details/52902844 Android开发常用工具类集合 android开发中为了避免重复造轮子, ...
- android 快速开发工具类,android面试知识点
项目地址:570622566/FastAndrUtils 简介:android 快速开发工具类 更多:作者 提 Bug 官网 标签: Fastandrutils 是一套整理修改整合的 and ...
最新文章
- Matlab实用程序--图形应用-枝干图
- BugKuCTF 加密 这不是摩斯密码
- 文件html怎么另存为wps,WPS文字中另存为功能详解(wps文字怎么保存到指定文件夹)...
- 安装Pywin32后无法正常引用pyd文件
- String.valueOf(Object)与Objects.toString(Object)
- zookeeper学习02 使用
- microbit与python编程_简单5步开始学习microbit编程-windows篇
- 在FL Studio中如何混音你的鼓组采样与旋律采样
- linux 基础笔记
- c语言操作题和答案,C语言上机操作题及答案.doc
- 解决AndroidStudio Locat侧边栏消失
- 斗鱼弹幕服务器连接协议,斗鱼弹幕服务器第三方接入协议v1 6 2.pdf
- 2021年黄石二中高考成绩查询,【黄石二中2018高考金榜】黄石二中2004届高考总结...
- ZeroTier + win10 远程桌面(替代TeamViewer)
- mysql触发器——NEW与OLD解析
- 【基础数学】单射、满射和双射的定义、区别
- 自己封装的CMusic类 【转】
- 自定义控件 仿微信朋友圈文字展开全文功能
- httpclient动态代理ip
- 小科普:什么是屏幕分辨率
热门文章
- arcgis如何将16bit栅格数据转换为8bit栅格数据
- 【路径规划】基于遗传算法求解多式联运运输问题matlab源码
- Docer实现Django Uwsgi部署
- wps自动插入文献_WPS参考文献自动生成方法教程
- 【cqbzoj1526】 分梨子 乱搞(不是dp) 解题报告 c++
- 基于msm8916移植lcd流程
- 问题解决:pdf打不开,出现Acrobat failed to connect to a DDE server问题
- selenium Gird
- -atime、-ctime、mtime、-newer
- oracle 压缩备份比率,Oracle 10g备份集压缩(Backupset Compression)