Exemplo n.º 1
0
        public static Bitmap Convert(object obj)
        {
            System.IO.MemoryStream stream = obj as System.IO.MemoryStream;

            Bitmap bm = null;

            if (stream != null)
            {
                byte[] img = stream.ToArray();
                IntPtr p   = Marshal.AllocCoTaskMem(Marshal.SizeOf(img[0]) * img.Length);
                Marshal.Copy(img, 0, p, img.Length);
                try
                {
                    bm = DibToImage.WithStream(p);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(p);
                }
            }

            return(bm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// ジャケット表示パネルにJpegファイルがドラッグされた時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void panelJacket_DragDrop(object sender, DragEventArgs e)
        {
            // 何も選択されていなかったら戻る
            if (listBoxMp3.SelectedIndex == -1)
            {
                return;
            }

            // ドロップされたデータがFileDrop型か調べる
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                ////ドロップされたデータがstring型か調べる
                //if( !e.Data.GetDataPresent( DataFormats.FileDrop ) )
                //{
                //	return;
                //}

                //ドロップされたデータ(string型)を取得
                string[] itemText = (string[])e.Data.GetData(DataFormats.FileDrop);

                // これだとクローズされずにロックされたままとなり、
                // 手動で画像ファイルを消去しようとしても explorer から怒られる
                //				Bitmap bm = (Bitmap)Image.FromFile( itemText[ 0 ] );

                // ↑の理由により FileStream オブジェクトを使用し、画像を読み込む
                System.IO.FileStream fs = new System.IO.FileStream(itemText[0],
                                                                   System.IO.FileMode.Open, System.IO.FileAccess.Read);
                Bitmap bm = (Bitmap)Image.FromStream(fs);
                fs.Close();

                bm = resizeBitmapTo1024(bm);

                string sTempBmp = Path.GetTempFileName();
                sTempBmp = Path.GetDirectoryName(sTempBmp) + "\\" + Path.GetFileNameWithoutExtension(sTempBmp) + ".bmp";

                // fs.Close() してしまったために保存できないんだとさ、そのための回避策
                bm = new Bitmap(bm);
                bm.Save(sTempBmp, System.Drawing.Imaging.ImageFormat.Bmp);
                string sTempJpeg = Path.GetTempFileName();
                sTempJpeg = Path.GetDirectoryName(sTempJpeg) + "\\" + Path.GetFileNameWithoutExtension(sTempJpeg) + ".jpg";

                BmpFileToJpegFile(sTempBmp, sTempJpeg);

                string sMp3File = null;
                foreach (int i in listBoxMp3.SelectedIndices)
                {
                    sMp3File = arrayMp3[i] as string;
                    try
                    {
                        TestSub(sMp3File, sTempJpeg);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                // 最後だけ選ばれている状態にする
                listBoxMp3.SelectedIndex = listBoxMp3.SelectedIndices[listBoxMp3.SelectedIndices.Count - 1];

                entryJacket(sMp3File);

                try
                {
                    File.Delete(sTempJpeg);
                    File.Delete(sTempBmp);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Html))
            {
                //ドロップされたデータ(string型)を取得
                string itemText = (string)e.Data.GetData(DataFormats.Html);
                MessageBox.Show("HTML ファイルはドロップできません", "エラー",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1,
                                MessageBoxOptions.DefaultDesktopOnly);
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Dib))
            {
                Bitmap bm = DibToImage.Convert(e.Data.GetData(DataFormats.Dib));
                bm = resizeBitmapTo1024(bm);

                string sTempBmp = Path.GetTempFileName();
                sTempBmp = Path.GetDirectoryName(sTempBmp) + "\\" + Path.GetFileNameWithoutExtension(sTempBmp) + ".bmp";
                bm.Save(sTempBmp, System.Drawing.Imaging.ImageFormat.Bmp);

                string sTempJpeg = Path.GetTempFileName();
                sTempJpeg = Path.GetDirectoryName(sTempJpeg) + "\\" + Path.GetFileNameWithoutExtension(sTempJpeg) + ".jpg";

                BmpFileToJpegFile(sTempBmp, sTempJpeg);


                string sMp3File = null;
                foreach (int i in listBoxMp3.SelectedIndices)
                {
                    sMp3File = arrayMp3[i] as string;
                    try
                    {
                        TestSub(sMp3File, sTempJpeg);
                        File.Delete(sTempJpeg);
                        File.Delete(sTempBmp);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                // 最後だけ選ばれている状態にする
                listBoxMp3.SelectedIndex = listBoxMp3.SelectedIndices[listBoxMp3.SelectedIndices.Count - 1];

                entryJacket(sMp3File);

                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Bitmap))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.CommaSeparatedValue))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.EnhancedMetafile))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.MetafilePict))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Locale))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.MetafilePict))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.OemText))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Riff))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Rtf))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Serializable))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.Tiff))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.SymbolicLink))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.UnicodeText))
            {
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.WaveAudio))
            {
                return;
            }
        }