| 
Rank: Member
 Groups: Guest
Joined: 1/12/2016(UTC)
 Posts: 23
 
 Thanks: 8 times
 | 
            
	      
                Hello, I have the following error when I try to convert a PSD file to JPG: "The Frame is Empty" Please see picture attached. Code Sample: Code:public static void Main(string[] args)
{
	const string path = @"D:\Paper-Bag-packaging-Mockup-psd.psd";
	const string pathOutput = @"D:\teste2.jpg";
	var file = File.ReadAllBytes(path);
	using (var imageStream = new MemoryStream(file))
	using (var exportedImageStream = new MemoryStream())
	using (var imageReader = ImageReader.Create(imageStream))
	using (var bitmap = imageReader.Frames[0].GetBitmap())
	{
		// merge photoshop layers
		if (imageReader.FileFormat == FileFormat.Psd)
		{
			((PsdReader)imageReader).MergeLayers(bitmap);
		}
		bitmap.Save(exportedImageStream, new JpegSettings { Quality = 85 });
		File.WriteAllBytes(pathOutput, exportedImageStream.GetBuffer());
	}
}
 Thank you! Kind Regards Edited by user Monday, May 16, 2016 8:57:35 AM(UTC)
 | Reason: Not specified | 
	
    | 
             | 
            
         | 
    |  | 
        
        
        
         
		   
        
            
            
	
    | 
Rank: Advanced Member
 Groups: Guest
Joined: 7/28/2003(UTC)
 Posts: 1,660
 
 Thanks: 5 timesWas thanked: 76 time(s) in 74 post(s)
 
 | 
            
	      
                Some PSD frames can contain no prerendered image data, that's why you receive exception when you request a bitmap: Code:imageReader.Frames[0].GetBitmap()
 Here is the corrected code: Code:public static void Main(string[] args)
{
	const string path = @"D:\Paper-Bag-packaging-Mockup-psd.psd";
	const string pathOutput = @"D:\teste2.jpg";
	var file = File.ReadAllBytes(path);
	using (var imageStream = new MemoryStream(file))
	using (var exportedImageStream = new MemoryStream())
	using (var imageReader = ImageReader.Create(imageStream))
	{
		Bitmap bitmap = null;
		try
		{
			// merge photoshop layers
			if (imageReader.FileFormat == FileFormat.Psd)
			{
				bitmap = new Bitmap();
				((PsdReader)imageReader).MergeLayers(bitmap);
			}
			else
			{
				bitmap = imageReader.Frames[0].GetBitmap();
			}
			bitmap.Save(exportedImageStream, new JpegSettings { Quality = 85 });
			File.WriteAllBytes(pathOutput, exportedImageStream.GetBuffer());
		}
		finally
		{
			if (bitmap != null)
				bitmap.Dispose();
		}
	}
}
 | 
| Best regards, Fedor Skvortsov
 | 
	
    | 
             | 
            
         | 
    |  | 
        
        
        
    
		
        
            
            
	
    | 
Rank: Member
 Groups: Guest
Joined: 1/12/2016(UTC)
 Posts: 23
 
 Thanks: 8 times
 |  | 
	
    | 
             | 
            
         | 
    |  | 
        
        
        
    
    
        Forum Jump
         
    
    You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.