Coder Social home page Coder Social logo

multi-image2one's Introduction

一个简单的 将多个image中的图片抓取 合成同一张图bitmap

主要实现思路 将imageView的图片缓冲开启,之后从中获取bitmap 加入到canvas上之后关闭缓冲区,然后将canvas保存成bitmap,如果你后续需要File保存到本地文件,或者是post到web都根据bitmap进行操作,但是一定要注意内存

private Bitmap SaveBitmap(ArrayList arrayList) { if (arrayList==null|arrayList.size()<=0) return null; Bitmap bmOverlay = Bitmap.createBitmap(arrayList.get(0).getWidth(), arrayList.get(0).getHeight(), Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmOverlay); for (ImageView imageView :arrayList){ imageView.setDrawingCacheEnabled(true); canvas.drawBitmap(imageView.getDrawingCache(), 0, 0, null); imageView.setDrawingCacheEnabled(false); } canvas.save(Canvas.ALL_SAVE_FLAG);// 保存 canvas.restore();// 存储 return bmOverlay; }

需要注意

  1. imageView.setDrawingCacheEnabled(true); 允许调用imageView的图片缓冲区 之后必须调用 setDrawingCacheEnabled(false)清空画图缓冲区,否则,下一次用getDrawingCache()方法回去图像时,还是原来的图像 2.由于是多个图片合成需要根据图片的多少、大小具体情况 确定是否需要开启独立线程去进行这个耗时操作o 后续会加入到此项目中 3.由于多图操作,可能造成内存溢出,需要注意回收内存,这个后续会加入到此项目中

multi-image2one's People

Contributors

eiffelyk avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.