In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to add a watermark to the picture in Android related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this Android article on how to add watermark to the picture will have a harvest, let's take a look at it.
Implementation method of adding Watermark to Android Picture
Watermarking (text and pictures) on the mobile phone uses some methods of Bitmap, Matrix and Canvas, which can achieve the effects of stretching, rotation, displacement and so on. The principle is very simple, that is, draw graphics, pictures, text and so on on the canvas Canvas to get the effect picture you want.
/ * add full-screen text / public static Bitmap drawCenterLable (Context context, Bitmap bmp, String text) {float scale = context.getResources () .getDisplayMetrics () .density; / / create an image of the same size Bitmap newBmp = Bitmap.createBitmap (bmp.getWidth (), bmp.getHeight (), Config.ARGB_8888); / / create canvas Canvas canvas = new Canvas (newBmp); canvas.drawBitmap (bmp, 0,0, null) / / draw the original picture canvas.save (); canvas.rotate (45); / / turn 45 degrees clockwise Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor (Color.argb (50,255,255,255)); / / White translucent paint.setTextSize (100scale); paint.setDither (true); paint.setFilterBitmap (true); Rect rectText = new Rect () / / get the width and height occupied by text, in pixels paint.getTextBounds (text, 0, text.length (), rectText); double beginX = (bmp.getHeight () / 2-rectText.width () / 2) * 1.4; / / the 45-degree angle value is 1.414 double beginY = (bmp.getWidth () / 2-rectText.width () / 2) * 1.4; canvas.drawText (text, (int) beginX, (int) beginY, paint) Canvas.restore (); return newBmp;}
Efficiency of png image verification using 44KB:
Long begin = System.currentTimeMillis (); Bitmap destBmp = ImageUtil.drawCenterLable (this, sourBitmap, "only for so-and-so company"); long end = System.currentTimeMillis (); Log.d ("brycegao", "time to watermark: + (end-begin) +" millisecond "); mWartermarkImage.setImageBitmap (destBmp)
Xiaomi 4 mobile phone output: D/brycegao: watermarking time: 69 milliseconds
Use 3m bytes of jpg image test to mark a watermark and report an OOM error.
Java.lang.OutOfMemoryError: Failed to allocate a 467251212 byte allocation with 16767536 free bytes and 110MB until OOM at dalvik.system.VMRuntime.newNonMovableArray (Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset (Native Method) at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:613) At android.graphics.BitmapFactory.decodeResourceStream (BitmapFactory.java:446) at android.graphics.BitmapFactory.decodeResource (BitmapFactory.java:469) at android.graphics.BitmapFactory.decodeResource (BitmapFactory.java:501) about "how to add watermarks to pictures in Android" This is the end of the article. Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to add watermarks to pictures in Android". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.