如何在Android上将一个大图像分成8个相等部分
问题描述:
我只是想将一个大的图像分解成一些相等的部分,如4,6或8。 我们可以做到吗? 实际上,我想将图像的每个部分作为独立图像存储在我的 可绘制文件夹中以供将来使用。如何在Android上将一个大图像分成8个相等部分
任何人都可以帮助我吗?
在此先感谢 苏尼特
答
你应该看看位图定义
与[这] [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)
编辑: 也许这个更简单
公共静态位图createBitmap(位图源,诠释的x,INT Y,INT宽度,高度INT)
应该是这个样子(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卡,这将有助于你看是否正确生成位图上创建位图的副本。
对不起,关于答案的格式,但是当我编辑它时,它很好... – 2010-11-16 07:50:25
我无法通过使用上述代码找到任何解决方案。你能帮我么。我如何才能实现它。 – 2010-11-16 09:13:46
谢谢我正在尝试这个。 – 2010-11-16 10:26:03