A method and electronic device for image compression are disclosed. The method includes: step A, for the initial grid, storing the color value (shown in the description) of the pixel with coordinates(l, h) in the image to the ni-th grid node with coordinates (xi, yi) in the grid; B, generating an optimized adaptive anisotropic mesh through an adaptive anisotropic mesh technology; Step C, restoring the original image by spline linear interpolation, checking whether the image pixel information stored in the optimized adaptive anisotropic mesh meets the requirements, if not, using the optimizedadaptive anisotropic mesh as a new initial mesh, and returning to step A for next iteration. The invention utilizes the characteristics of the finite element mesh in the computational mechanics and based on the adaptive anisotropic mesh optimization technology, is applied in the image compression technology, and greatly saves the storage space of the image. This technique is not only limited to two-dimensional image compression, but also extends to three-dimensional image compression applications.