Android的替代java.awt中(BufferedImage的和光栅) [英] Android alternative to java.awt (BufferedImage and Raster)

查看:1263
本文介绍了Android的替代java.awt中(BufferedImage的和光栅)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最后一年的项目我开发一个Android应用程序,可以捕获叶的形象,确定哪些类型的树它是从哪里来的。我有一个接近完成PC版(Java开发)和我开始移植到了Android的过程。虽然的BufferedImage 和Raster弥补我的计划的一个关键部分,这是一个问题,因为 java.awt中的在失踪Android的,所以这意味着我必须改变图书馆。

for my final year project I am developing an android app that can capture the image of a leaf and identify what type of tree it came from. I have a nearly completed PC version (developed in java) and i am starting the process of porting it to android. Although BufferedImage and Raster make up a key part of my program, this is a problem because java.awt is missing in android, so this means i have to alter the library.

我使用的是由我的讲师开发的库,下面的方法是BufferedImage转换为IntImage使用光栅(即用于整个封装类型)。

I am using a library that was developed by my lecturer, the method below converts a BufferedImage to an IntImage(a type that is used throughout the package) using Raster.

我基本上问是否还有任何Android的替代品 java.awt中的,我可以使用?

I'm basically asking are there any android alternatives to java.awt that i can use?

这里的code:

public static int[][] readAsInts(String fileName) throws IOException {
    int[][] pixels;

    System.out.println("File: " + fileName);

    String [] types = ImageIO.getReaderFileSuffixes();
    for (int l = 0; l < types.length; l++) {
        System.out.println("Type " + l + ": " + types[l]);
    }
    File f = new File(fileName);
    BufferedImage bi;
    bi = ImageIO.read(f);

    int cols = bi.getWidth();
    int rows = bi.getHeight();

    System.err.println("Number of bands: " + bi.getRaster().getNumBands());
    Raster rast = bi.getRaster();

    pixels = new int[rows][cols];
    for (int r = 0; r < rows; r++) {
        rast.getSamples(0, r, cols, 1, 0, pixels[r]);
    }
    return pixels;
} // readAsInts

谢谢你们!

编辑:对于谁不知道栅格存储用于BufferedImage的像素值,以及带(红,绿,蓝,阿尔法)的数目,所以这个算法取像素值的广告并将其存储在一个二维数组(像素)。

For anyone who doesn't know the raster stores the pixel values for the BufferedImage, along with the number of bands (red, green, blue, alpha), so this algorithm takes the pixel values ad stores them in a 2d array (pixels).

推荐答案

听起来像是你只是想用位图工作,并能够操纵像素本身在数组中。该 位图 一流想到连同其<一个href="http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29"相对=nofollow> 的getPixels 方法。但请记住,你有更多的内存有限的移动设备上。这很容易有大位图工作时遇到内存不足的问题。

Sounds like you just want to work with bitmaps and be able to manipulate the pixels themselves in an array. The Bitmap class comes to mind along with its getPixels method. Remember though that you have much more limited memory on a mobile device. It's easy to run into out of memory problems when working with large bitmaps.

另一途径是使用NDK的。我没有太多的经验有,但 AndroidBitmap_lockPixels AndroidBitmap_unlockPixels 可能是一个良好的开端。

Another route would be to use the NDK. I don't have much experience there, but AndroidBitmap_lockPixels and AndroidBitmap_unlockPixels are probably a good place to start.

最后,还应该执行pretty的还有另一种选择是使用 RenderScript

Lastly, yet another option that should perform pretty well is to use RenderScript.

如果你正在寻找做的是将图像加载到一个 INT 阵列虽然, Bitmap.getPixels 应该是相当足够了。

If all you're looking to do is load an image into an int array though, Bitmap.getPixels should be quite sufficient.

这篇关于Android的替代java.awt中(BufferedImage的和光栅)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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