For more details, please visit Rotate or Crop PSD Image using C#
Last active
December 23, 2021 05:57
Crop or Rotate a PSD file Programmatically with C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String sourceFile = "sample.psd"; | |
String destName = "Cropping-PSD_out.jpg"; | |
// Load an existing image into an instance of RasterImage class | |
RasterImage rasterImage = (RasterImage)Image.Load(sourceFile); | |
// Cache the image for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Create an instance of Rectangle class with desired size. | |
Rectangle rectangle = new Rectangle(20, 20, 20, 20); | |
// Perform the crop operation on object of Rectangle class | |
rasterImage.Crop(rectangle); | |
// Save the results to disk | |
rasterImage.Save(destName, new ImageOptions.JpegOptions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an existing image into an instance of RasterImage class | |
RasterImage rasterImage = (RasterImage)Image.Load("Test.psd"); | |
// Before cropping, the image should be cached for better performance | |
if (!rasterImage.IsCached) | |
{ | |
rasterImage.CacheData(); | |
} | |
// Define shift values for all four sides | |
int leftShift = 10; | |
int rightShift = 10; | |
int topShift = 10; | |
int bottomShift = 10; | |
// Based on the shift values, apply the cropping on image Crop method will shift the image bounds toward the center of image and Save the results to disk | |
rasterImage.Crop(leftShift, rightShift, topShift, bottomShift); | |
// Save output in JPEG,PSD or any other format. | |
rasterImage.Save("output.jpg", new ImageOptions.JpegOptions()); | |
rasterImage.Save("output.psd", new ImageOptions.PsdOptions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String sourceFile = "sample.psd"; | |
String destName = "Rotate-PSD_out.jpg"; | |
// Load input PSD image file | |
RasterImage image = (RasterImage)Image.Load(sourceFile); | |
// Before rotation, the image should be cached for better performance | |
if (!image.IsCached) | |
{ | |
image.CacheData(); | |
} | |
// Rotate the PSD image on 20 degree angle while keeping the image size proportional with red background color | |
image.Rotate(20f, true, Color.Red); | |
// Save the result to a new file | |
image.Save(destName, new ImageOptions.JpegOptions()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment