如何在android中将大图像分成8个相等的部分

时间:2010-11-16 07:35:31

标签: android


 我只想将一张大图像分成4,6或8等相同的部分。  我们能做到吗?  实际上我想将图像的每个部分存储为我的单独图像  drawable文件夹供将来使用。

任何人都可以帮助我吗?

提前致谢  苏尼特

1 个答案:

答案 0 :(得分:0)

您应该查看位图定义

用[this] [1]你应该可以做到

public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)

[1]:http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap,int,int,int,int,android.graphics.Matrix,boolean)

编辑: 也许这个更简单

  

public static Bitmap createBitmap(Bitmap source,int x,int y,int width,int height)

看起来应该是这样的(除了4,你必须弄清楚你的循环才能让它在4,6,8上工作......

Bitmap source = ...;
int halfWidth = source.getWidth()/2;
int halfHeight = source.getHeight()/2; 
Bitmap topleft, topright, bottomleft, bottomright;
topleft = createBitmap(source,0,0,halfWidth ,halfHeight);
topright= createBitmap(source,halfWidth ,0,halfWidth ,halfHeight); 
bottomleft= createBitmap(source ,0,halfHeight,halfWidth ,halfHeight);
bottomright = createBitmap(source ,halfWidth ,halfHeight,halfWidth ,halfHeight);

我没有时间在我的电脑上创建测试代码,这应该让你开始。

也试试这个

try {
                FileOutputStream out = new FileOutputStream("/sdcard/image"+num+".png");
                mBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
            } catch (Exception e) {
                e.printStackTrace();
            }

它会在你的SD卡上创建一个位图副本,它可以帮助你查看是否正确生成了位图。