android图片处理,androidapp的开发流程

本文详细介绍了Android中图片的处理技术,包括图片切割、灰度处理、缩略图生成、镜像操作以及图片透明度调整。示例代码展示了如何使用Java进行Bitmap操作,如分割、变灰、创建缩略图以及使用Matrix实现镜像效果。同时,还提供了加载、缩放、平均分割和绘制带边框文字的方法。
摘要由CSDN通过智能技术生成

一个是ImageSplitter类,有一个静态方法split,传入的参数是要切割的Bitmap对象,和横向和竖向的切割片数。比如传入的是3、3,则横竖向都切割成3片,最终会将整个图片切割成3X3=9片。

Java代码   收藏代码

  1. import java.util.ArrayList;

  2. import java.util.List;

  3. import android.graphics.Bitmap;

  4. public class ImageSplitter {

  5. public static List split(Bitmap bitmap, int xPiece, int yPiece) {

  6. List pieces = new ArrayList(xPiece * yPiece);

  7. int width = bitmap.getWidth();

  8. int height = bitmap.getHeight();

  9. int pieceWidth = width / 3;

  10. int pieceHeight = height / 3;

  11. for (int i = 0; i < yPiece; i++) {

  12. for (int j = 0; j < xPiece; j++) {

  13. ImagePiece piece = new ImagePiece();

  14. piece.index = j + i * xPiece;

  15. int xValue = j * pieceWidth;

  16. int yValue = i * pieceHeight;

  17. piece.bitmap = Bitmap.createBitmap(bitmap, xValue, yValue,

  18. pieceWidth, pieceHeight);

  19. pieces.add(piece);

  20. }

  21. }

  22. return pieces;

  23. }

  24. }

1、图标加灰色过滤;

2、android的图片资源默认是静态的,单实例;如果两个IM好友的头像一样,最简单的都是用的软件自带头像,有一个在线,一个离线,直接改变头像的灰度,则两个用户的头像都会变灰或者在线,答案是:Drawable.mutate()。

Java代码   收藏代码

  1. Drawable mDrawable = context.getResources().getDrawable(R.drawable.face_icon);

  2. //Make this drawable mutable.

  3. //A mutable drawable is guaranteed to not share its state with any other drawable.

  4. mDrawable.mutate();

  5. ColorMatrix cm = new ColorMatrix();

  6. cm.setSaturation(0);

  7. ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);

  8. mDrawable.setColorFilter(cf);

生成缩略图,抠自android launcher源码:

Java代码   收藏代码

  1. /*

  2. * Copyright © 2008 The Android Open Source Project

  3. *

  4. * Licensed under the Apache License, Version 2.0 (the “License”);

  5. * you may not use this file except in compliance with the License.

  6. * You may obtain a copy of the License at

  7. *

  8. *      http://www.apache.org/licenses/LICENSE-2.0

  9. *

  10. * Unless required by applicable law or agreed to in writing, software

  11. * distributed under the License is distributed on an “AS IS” BASIS,

  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  13. * See the License for the specific language governing permissions and

  14. * limitations under the License.

  15. */

  16. package com.android.launcher;

  17. import android.graphics.drawable.BitmapDrawable;

  18. import android.graphics.drawable.Drawable;

  19. import android.graphics.drawable.PaintDrawable;

  20. import android.graphics.Bitmap;

  21. import android.graphics.PixelFormat;

  22. import android.graphics.Canvas;

  23. import android.graphics.PaintFlagsDrawFilter;

  24. import android.graphics.Paint;

  25. import android.graphics.Rect;

  26. import android.content.res.Resources;

  27. import android.content.Context;

  28. /**

  29. * Various utilities shared amongst the Launcher’s classes.

  30. */

  31. final class Utilities {

  32. private static int sIconWidth = -1;

  33. private static int sIconHeight = -1;

  34. private static final Paint sPaint = new Paint();

  35. private static final Rect sBounds = new Rect();

  36. private static final Rect sOldBounds = new Rect();

  37. private static Canvas sCanvas = new Canvas();

  38. static {

  39. sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值