public override FileTypeMan.OpenResult Open(string path) { try { CPSD psd = new CPSD(); int nResult = psd.Load(path); switch (nResult) { case -1: return(new FileTypeMan.OpenResult { ErrorMessage = TypeName + " - " + LangMan.Get("unable-open-file") + ": " + Path.GetFileName(path) }); default: return(new FileTypeMan.OpenResult { Bmp = Image.FromHbitmap(psd.GetHBitmap()) }); } } catch { return(new FileTypeMan.OpenResult { ErrorMessage = TypeName + " - " + LangMan.Get("unable-open-file") + ": " + Path.GetFileName(path) }); } }
public static Bitmap myImg(string fpath) { CPSD psd = new CPSD();//新取一个变量 int res = psd.Load(fpath); if (res == 0) { return(Bitmap.FromHbitmap(psd.GetHBitmap())); } else { Bitmap bm = new Bitmap(2, 2); return(bm); } }
public Bitmap ConstructBitmap(Stream stream, int sideSize) { File.WriteAllText("c:\\sil.txt", "ConstructBitmap(Stream stream, int sideSize) init"); // return null; try { // MessageBox.Show("1. adim"); stream.Position = 0; CPSD psd = new CPSD(); psd.Load(stream); // MessageBox.Show("3. adim"); //FileStream tmpStrm = new FileStream(@"c:\sil.psd", FileMode.Create); //stream.CopyTo(tmpStrm); Bitmap psdBitmap = Image.FromHbitmap(psd.GetHBitmap()); Size size = new Size(); if (psdBitmap.Width > psdBitmap.Height) { size.Height = psdBitmap.Height * sideSize / psdBitmap.Width; size.Width = sideSize; } else { size.Width = psdBitmap.Width * sideSize / psdBitmap.Height; size.Height = sideSize; } // ((Bitmap)ThumbCreator.ThumbCreator.ResizeImage(psdBitmap, size)).Save(@"c:\sil.bmp"); return ThumbCreator.ThumbCreator.ResizeImage(psdBitmap, size) as Bitmap; //using (var Thumbnail = new Bitmap(cx, cx)) //{ // using (var G = Graphics.FromImage(Thumbnail)) // { // G.Clear(Color.Red); // } // hBitmap = Thumbnail.GetHbitmap(); //} } catch { } // A dirty cop-out. return Resource1.Dummy; }
public static Bitmap ParsePsd(string path) { try { CPSD psd = new CPSD(); int nResult = psd.Load(path); switch (nResult) { case -1: CurrentError = Error.UnableToOpen; return(null); default: CurrentError = Error.NoError; return(Image.FromHbitmap(psd.GetHBitmap())); } } catch { CurrentError = Error.UnableToOpen; return(null); } }
public void OpenPsdFile(string FileName) { int nResult = psd.Load(FileName); if (nResult == 0) { int nCompression = psd.GetCompression(); string strCompression = "Unknown"; switch (nCompression) { case 0: strCompression = "Raw data"; break; case 1: strCompression = "RLE"; break; case 2: strCompression = "ZIP without prediction"; break; case 3: strCompression = "ZIP with prediction"; break; } label1.Text = string.Format("Image Width: {0}px\r\nImage Height: {1}px\r\n" + "Image BitsPerPixel: {2}\r\n" + "Resolution (pixels/inch): X={3} Y={4}\r\n", psd.GetWidth(), psd.GetHeight(), psd.GetBitsPerPixel(), psd.GetXResolution(), psd.GetYResolution()); label1.Text += "Compression: " + strCompression; pictureBox1.Image = System.Drawing.Image.FromHbitmap(psd.GetHBitmap()); } else if (nResult == -1) { MessageBox.Show("Cannot open the File"); } else if (nResult == -2) { MessageBox.Show("Invalid (or unknown) File Header"); } else if (nResult == -3) { MessageBox.Show("Invalid (or unknown) ColourMode Data block"); } else if (nResult == -4) { MessageBox.Show("Invalid (or unknown) Image Resource block"); } else if (nResult == -5) { MessageBox.Show("Invalid (or unknown) Layer and Mask Information section"); } else if (nResult == -6) { MessageBox.Show("Invalid (or unknown) Image Data block"); } }