在同一文本文件r,g,b中的Imageview中写入像素到图像的值

时间:2017-10-06 19:06:49

标签: java android android-imageview pixel

如何在同一文本文件中写入r,g,b的值? 此代码为不同文本文件中的所有像素写入r,g,b值。

我需要在同一文本文件中获取所有像素值

(图片视图中的此图片) .................................................. .........

android #pixel

    public void buttonsave(View view){
    BitmapDrawable abmp = (BitmapDrawable) ivImage.getDrawable();
    bmp = abmp.getBitmap();
    operation = 
    Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),bmp.getConfig());
    double width=(bmp.getWidth())*0.25;
    double height=(bmp.getHeight())*0.25;
    File file=new File(path+"/savedFile.txt");

    for(int i=0; i<bmp.getWidth(); i++){
        for(int j=0; j<bmp.getHeight(); j++){
            int p = bmp.getPixel(i, j);
            int r = Color.red(p);
            int g = Color.green(p);
            int b = Color.blue(p);
            int alpha = Color.alpha(p);
            int z=0;
            operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));

            //setPixels(int[] pixels, int offset, int stride, int x, int y, 
           int width, int height)
            w=String.valueOf(i);
            h=String.valueOf(j);

            int numbers [  ]={r,g,b};

            String numbersArr[] = new String[numbers.length];
            for(int l=0; l<numbers.length; l++){
                numbersArr[z] = String.valueOf(numbers[l]);
                z++;

            }

            Save(file,numbersArr);
   Toast.makeText(getApplicationContext(),"saved",Toast.LENGTH_LONG).show();
        }}

}

public static void Save(File file, String[] data) {
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        try {
            for (int i = 0; i < data.length; i++) {
                fos.write(data[i].getBytes());
                if (i < data.length - 1) {
                    fos.write("".getBytes());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } finally {
        try {
            fos.close();
        } catch (IOException e) {
            e.printStackTrace(); }
    }}

0 个答案:

没有答案