Implementing a basic zoom mode for my image

So, I have an image that I open in a window with SDL2. I want to implement a zoom function for the image that works as following: I click on two points of the image and I make a rectangle with those points as opposite corners. Then I make a copy of the rectangle and update the window to show the part of the image I selected, and this new image has a bigger width and height than the rectangle I chose because it will be the height and the width of the whole window. I can detect the mouse clicks, and from the mouse clicks calculate the top left corner of the rectangle in x and y coordinates. However, I don’t know how to make a copy of the pixels in those rectangles, nor how to make the window now show the zoomed in part. I’ve been googling a lot but I don’t know what functions to use or how to code my own. How would I write such a function?

Here’s what I have so far. The image I want to be able to zoom into is “map.jpg”

SDL_Window *window = NULL;
window = SDL_CreateWindow("WarmingUp", TOP_LEFT_CORNER_X,
                      TOP_LEFT_CORNER_Y, IMAGE_WIDTH, IMAGE_HEIGHT, 0);
if(window == NULL){
    printf("Erro a abrir janela gráfica\n");

SDL_Renderer *renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL){
    printf("Erro a criar renderer\n");

SDL_Surface *jpgSurface = NULL;
jpgSurface = IMG_Load("map.jpg");
if(jpgSurface == NULL){
    printf("Erro a abrir imagem\n");
SDL_Texture *jpgTexture = NULL;
jpgTexture = SDL_CreateTextureFromSurface(renderer, jpgSurface);
if(jpgTexture == NULL){
    printf("Erro a criar superfície através de imagem\n");
SDL_Event e;
SDL_RenderCopy(renderer, jpgTexture, NULL, NULL);    
        if(e.type == SDL_QUIT)
            quit = 1;

Sorry I am realy a noob.

You need to provide new source coordinates for the texture. In the code above you are using NULL parameter for RenderCopy, which means that whole texture is copied.

If the source texture has different width or height than your window, you need to do some calculations. Perhaps something like:

float x = (float)mouseX / windowWidth;
float y = (float)mouseY / windowHeight;

Then multiply by textureWidth and textureHeigth to get new corner coordinates for texture.