0

In the main part, I rotated the image. Then I wrote a code for writing my image to in project file as a jpeg file. I couldn't do it.

Here is my code:

They are some definitions and libraries I used. (I also added standard libraries.)

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define CHANNEL_NUM 3



int main() {
     .
     .
     .
     write(&out_image); // calling by reference

}

After this part, I want to write my image as a jpg file. So this is the writing part:

int write(unsigned char *rgb_image)
 {
    
    int width =400; 
    int height = 400;
    
    rgb_image = malloc(width*height*CHANNEL_NUM);       
    stbi_write_jpg("rotated_image", width, height, CHANNEL_NUM, rgb_image, width*CHANNEL_NUM);

    return 0;
}

I am not sure about the second part so I share it with you. By the way, I don't get any errors in both functions. (main and write)

If you want the full code, let me know in the comment section. I can share my main function too.

  • 1
    We don't want full code, but we want a [mre] – klutt Feb 24 '21 at 16:31
  • The last parameter to stbi_write_jpg() is quality, an int from 1 to 100% quality (=compression). Anything over 100 is set to 100. You allocate rgb_image right before writing it, and that memory isn't initialized to anything. Is that what you meant to do? – JohnH Feb 24 '21 at 18:37

0 Answers0