如何打破一个大的图像到Android的8等份 [英] how to break a large image into 8 equal parts in android

查看:134
本文介绍了如何打破一个大的图像到Android的8等份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
 我只是想打破一个大的图像为若干等份像4,6或8。
 我们能做到吗?
 其实我想图像的每个部分存储为一个单独的图像我
 绘制文件夹以备将来使用。


i just want to break a large image into some equal parts like 4, 6 or 8. can we do it? actually i want to store every parts of image as a separate image in my drawable folder for future use.

任何一个可以帮助我吗?

can any one help me?

在此先感谢
 苏尼特

Thanks in advance sunit

推荐答案

您应该看看定义位图

与[这里] [1]你应该能够做到这一点。

with [this][1] you should be able to do it

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

[1]:<一href=\"http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap\" rel=\"nofollow\">http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap, INT,INT,INT,INT,android.graphics.Matrix,布尔)

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

编辑:
也许这一个是简单

edit: maybe this one is simpler

公共静态位图createBitmap(位图源,诠释的x,INT Y,INT宽度,高度INT)

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

应该是这个样子(4分,你必须找出你的循环,使其对4,6,8工作...

should look something like this (divided in 4, you'll have to work out your loops to make it work on 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);

我没有时间到我的电脑放这应该让你开始创建一个测试code。

I don't have time to create a test code on my computer put this should get you started.

也可以尝试这种

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

这将创建你的SD卡位图,这将有助于你看看是否正确生成位图的副本。

it will create a copy of the bitmap on your sdcard that will help you see if the bitmap is generated correctly.

这篇关于如何打破一个大的图像到Android的8等份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆