How to upscale an image without affecting pixel aspect ratio? For example, if we upscale an image from 100 x 100 to 400 x 300 then we see the pixel stretch in the image which I want to eliminate.

The easiest way I could think is to crop the image to maintain the pixel aspect ratio i.e. upscaling to 300 x 300 or 400 x 400

Edit (Clarification): I want upscale an image without causing pixels to stretch, upsampling algorithms like nearest neighbor, bilinear interpolation, etc cause pixel stretching, especially when there is a change in aspect ratio e.g. from 1:1 to 16:9
Popular cheap methods are:


Letterboxing

Cropping

A combined method: cropping, overlapped by the letterboxed image



The combined method works surprisingly well in videos, and people are quite accustomed to viewing such videos.

Photoshop and others also have smart content-aware scaling/resizing algorithms that re-organize or generate image content to the new image size. I don't have PhotoShop to demonstrate it with, but here is a video from Adobe.