Android project notepad (12), android Project

Source: Internet
Author: User

Android project notepad (12), android Project
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020

In Android UI development, image scaling is often encountered. For example, in notepad, the current images are relatively large. If the source image is directly placed on the screen without scaling, the entire screen will be fully occupied, and sometimes the image is bigger than the screen, and the whole image cannot be displayed completely. Therefore, you must scale the image. But how can you scale the image, to maintain the aspect ratio of the source image, the best way is to restrict the proportional scaling, that is, proportional scaling, I believe everyone has used the zoom function in PS. One option is to constrain the zoom ratio, that is, to maintain the aspect ratio, that is, proportional scaling.

Zoom before scaling

The idea of proportional scaling is very simple, that is, to maintain the aspect ratio during the scaling process, the Code is as follows:

// Proportional scaling image private Bitmap resize (Bitmap bitmap, int S) {int imgWidth = bitmap. getWidth (); int imgHeight = bitmap. getHeight (); double partion = imgWidth * 1.0/imgHeight; double sqrtLength = Math. sqrt (partion * partion + 1); // new thumbnail size double newImgW = S * (partion/sqrtLength); double newImgH = S * (1/sqrtLength ); float scaleW = (float) (newImgW/imgWidth); float scaleH = (float) (newImgH/imgHeight); Matrix mx = new Matrix (); // scale the original image mx. postScale (scaleW, scaleH); bitmap = Bitmap. createBitmap (bitmap, 0, 0, imgWidth, imgHeight, mx, true); return bitmap ;}
S is the maximum pixel to which the length and width are scaled.

Today I will try to add a border effect to the image. Of course, here I simply add a line border, or I can add other nice borders to the image. first look at it:

In fact, the idea of adding a border to an image is to draw a rectangle around the image. The Code is as follows:

// Add a border to the image and return the public Bitmap getBitmapHuaSeBianKuang (Bitmap bitmap) {float frameSize = 0.2f; Matrix matrix = new Matrix (); // used for base map Bitmap bitmapbg = Bitmap. createBitmap (bitmap. getWidth (), bitmap. getHeight (), Bitmap. config. ARGB_8888); // sets the basemap to Canvas canvas Canvas = new canvas (bitmapbg); Canvas. setDrawFilter (new PaintFlagsDrawFilter (0, Paint. ANTI_ALIAS_FLAG | Paint. FILTER_BITMAP_FLAG); float scale_x = (bitmap. getWidth ()-2 * frameSize-2) * 1f/(bitmap. getWidth (); float scale_y = (bitmap. getHeight ()-2 * frameSize-2) * 1f/(bitmap. getHeight (); matrix. reset (); matrix. postScale (scale_x, scale_y); // process the Photo size (minus the size of the border) bitmap = Bitmap. createBitmap (bitmap, 0, 0, bitmap. getWidth (), bitmap. getHeight (), matrix, true); Paint paint = new Paint (); paint. setColor (Color. WHITE); paint. setStrokeWidth (1); paint. setStyle (Style. FILL); // draw the basemap border canvas. drawRect (new Rect (0, 0, bitmapbg. getWidth (), bitmapbg. getHeight (), paint); // draw a gray border paint. setColor (Color. BLUE); canvas. drawRect (new Rect (int) (frameSize), (int) (frameSize), bitmapbg. getWidth ()-(int) (frameSize), bitmapbg. getHeight ()-(int) (frameSize), paint); canvas. drawBitmap (bitmap, frameSize + 1, frameSize + 1, paint); return bitmapbg ;}



Who will be responsible for the Android notepad project? We are going to take the Android course. We need to prepare an Android notepad project at the end of the course.

Android Notepad program source code
Blog.csdn.net/..096216
 
Android notepad and Android notepad

There are a lot of Android mobile phone notepad software. Which of the following Landlords prefer to use it on their own. I know several easy-to-use notepad software and recommend it to the landlord.

Some software can be downloaded in [Android park]. You only need to enter the notepad to find it.

[Handwritten notepad]
HandCalendar is a notebook, notebook, and notebook that supports handwriting. It also supports saving recorded content to the calendar. The handwriting function of the software is relatively powerful. It supports 10 colors and 3 pen styles, and supports a maximum of three erasers to cancel the function.

[AK Notepad]
AK notepad is a powerful text document editing software. In addition to editing, reading, and writing documents and viewing TXT documents, the software also allows you to share event reminders with others through text messages, emails, and mobile phone alarms.

[With handwriting]
Hand-writing is definitely the most convenient convenience software, and the original smart scaling. Supports both handwriting (Original Handwriting) and keyboard input. Features: 1. You can remember big things on a small screen and use the original handwriting keyboard mixed-mode.
2. task management, notes, calendar, alarm clock, MMS, and schedule 3. Free graffiti, illustrations, photo notes, and voice notes on photos 4. widgets read the current notebook directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.