小编Him*_*rma的帖子

将简单图像转换为灰度

我正在尝试将普通彩色图像转换为灰度图像。代码非常简单,但不知道为什么会出现错误。我只是逐个像素地更改颜色值,然后将其存储在新的位图中。错误即将到来我正在尝试将像素设置为新位图。

 Bitmap c=BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + "/1.jpg");

    int width=c.getWidth();
    int height=c.getHeight();
    int A,B,R,G;
    int pixel;




    for(int x = 0; x < width; x++) {
        for(int y = 0; y < height; y++) {
            // get one pixel color

       //     pixel = c.getPixel(x, y);
            // retrieve color of all channels

  //          A = Color.alpha(c.getPixel(x, y));
            R = Color.red(c.getPixel(x, y));
            G = Color.green(c.getPixel(x, y));
            B = Color.blue(c.getPixel(x, y));

            // take conversion up to one single value
            R = G = B = (int)(0.299 * …
Run Code Online (Sandbox Code Playgroud)

android image bitmap

4
推荐指数
1
解决办法
2722
查看次数

快速排序 - 中间枢轴实现奇怪的行为

我正在尝试使用在线提供的各种教程以枢轴值作为向量的中间元素来实现快速排序。尽管它适用于某些样本,但在某些样本中我无法获得排序向量。

示例 - 输入 {5,3,8,6,1,0,4} 但输出为 {0,3,4,5,1,6,8}

快速排序实现

void quickSortMiddle(vector<int> &a, int left, int right)
{
    if(left >=right) return;

    int leftI = left;
    int rightI = right;

    int pivot = left + (right - left)/2;

    while(leftI<=rightI)
    {
        while(a[leftI] < a[pivot] )leftI++;
        while(a[rightI] > a[pivot])rightI--;

        if(leftI <=rightI)
        {
            swap(a[leftI], a[rightI]);
            leftI++;
            rightI--;
        }
    }

    if(left <= rightI)quickSortMiddle(a,left,rightI);
    if(leftI <= right)quickSortMiddle(a,leftI,right);
}
Run Code Online (Sandbox Code Playgroud)

以下是我在每次实施后得到的输出

5340168

0345168

0345168

0345168

final : 
0345168
Run Code Online (Sandbox Code Playgroud)

c++ sorting algorithm quicksort

3
推荐指数
1
解决办法
7067
查看次数

无法在SD卡中创建文件

我试图将位图保存到文件,然后将其保存在SD卡上.这是我的代码:

String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path, "Jhs"+".jpg");
file.mkdir();
OutputStream fOut;
try {
    fOut = new FileOutputStream(file);
    BitmapMatrix convMatrix = new BitmapMatrix(0);
    convMatrix.result.compress(Bitmap.CompressFormat.JPEG, 100, fOut);

    fOut.flush();
    fOut.close();
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

此代码也在一个不扩展Activity的类中.我只是给出了这个信息,认为可能存在一些问题.这是我的LogCat

05-01 18:00:22.555: W/System.err(31392): java.io.FileNotFoundException:           /mnt/sdcard/Jhs.jpg (Permission denied)
05-01 18:00:22.555: W/System.err(31392):    at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
05-01 18:00:22.555: W/System.err(31392):    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
05-01 18:00:22.555: W/System.err(31392):    at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
05-01 18:00:22.555: W/System.err(31392): …
Run Code Online (Sandbox Code Playgroud)

android file bitmap sd-card

2
推荐指数
1
解决办法
7007
查看次数

标签 统计

android ×2

bitmap ×2

algorithm ×1

c++ ×1

file ×1

image ×1

quicksort ×1

sd-card ×1

sorting ×1