Beispiel #1
0
 /// <summary>
 /// カードをひっくり返す。
 /// </summary>
 public void ReverseCard()
 {
     if (side == Side.front)
     {
         side = Side.back;
         IntPtr hbitmap = backImageBitmap.GetHbitmap();
         imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         DeleteObject(hbitmap);
     }
     else
     {
         side = Side.front;
         IntPtr hbitmap = ImageBitmap.GetHbitmap();
         imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
         DeleteObject(hbitmap);
     }
 }
Beispiel #2
0
        public static Bitmap backImageBitmap;//裏面のビットマップ。裏面は共通なのでクラス変数にする。
        /// <summary>
        /// コンストラクタで画像イメージを設定する。
        /// 全絵柄の1枚絵をクラス変数に保持して部分イメージを切り出して割り当てる。
        /// </summary>
        /// <param name="suit"></param>
        /// <param name="number"></param>
        public Card(Suit suit, int number)
        {
            this.suit   = suit;
            this.number = number;
            this.side   = Side.back;
            const int width = 60; //カード1枚の幅
            const int hidth = 90; //カード1枚の高さ

            if (originalBitmap == null)
            {
                originalBitmap = new Bitmap(480, 630);
                var originalImage = Image.FromFile(imgURL);
                originalBitmap  = (Bitmap)originalImage;
                backImageBitmap = ImageRoi(originalBitmap, new Rectangle(7 * width, 6 * hidth, width, hidth));
            }

            int x;
            int y;

            if (suit.Equals(Suit.jocker))
            {
                x = 4;
                y = 6;
            }
            else
            {
                if (number < 8)
                {
                    x = (int)suit;
                    y = number - 1;
                }
                else
                {      //元画像が8から次の列になっているので読み込み位置をずらす
                    x = (int)suit + 4;
                    y = number - 8;
                }
            }
            ImageBitmap = ImageRoi(originalBitmap, new Rectangle(x * width, y * hidth, width, hidth));//一枚あたりの大きさ
            IntPtr hbitmap = ImageBitmap.GetHbitmap();

            imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            DeleteObject(hbitmap);
        }