c ++:尝试将创建的图像保存为.jpg文件,但图像不会打开

时间:2016-11-26 19:56:02

标签: c++ algorithm visual-studio physics particles

我在visual studio中使用c ++,我有一个为n体模拟问题创建图像的算法。算法本身有效但我需要存储图像才能证明它有效。我尝试了很多不同的方法(已在代码中注释掉),试图实现这一目标。我对c ++不太熟悉,而且代码是给我的,所以任何帮助或建议都会非常感激。

我尝试存储图像的功能是PrintParticle()函数:

public function actionUpdate($id) {
    $model = $this->findModel($id);

    if ($model->load(Yii::$app->request->post())) {
        $x = Yii::$app->request->post('Book');
        $new_author = $x['author_id'];
        if (!is_numeric($new_author)) {
            $author = new Author();
            $author->name = $new_author;
            $author->save();
            $model->author_id = $author->id;
        }
        if ($model->save()) {
            return $this->redirect(['index']);
        }
    } else {
        return $this->render('update', [
                    'model' => $model,
                    'categories' => BookCategory::find()->active()->all(),
                    'publishers' => Publisher::find()->all(),
                    'copirights' => Copiright::find()->all(),
                    'authors' => Author::find()->all(),
        ]);
    }
}

1 个答案:

答案 0 :(得分:3)

JPEG需要一种特殊的文件格式,您的代码无法实现。我建议您先从搜索图像格式的库中开始,或者实现自己的编解码器。

只需将文字写入文件并将其调用即可#34; .jpg"不会工作。