// Okuduğumuz resmi 16 eş parçaya ayıran fonksiyon private void divideThePicture(Image img) { bmps = new Bitmap[4, 4]; btnBitmap = new Bitmap[4, 4]; int widthThird = (int)((double)img.Width / 4.0 + 0.5); int heightThird = (int)((double)img.Height / 4.0 + 0.5); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { int index = (i * 4 + j) + 1; bmps[i, j] = new Bitmap(widthThird, heightThird); Graphics g = Graphics.FromImage(bmps[i, j]); g.DrawImage(img, new Rectangle(0, 0, widthThird, heightThird), new Rectangle(j * widthThird, i * heightThird, widthThird, heightThird), GraphicsUnit.Pixel); // Burada butona göre boyutlandırma yapıyoruz ve buton nesnelerinin içerisine yerleştiriyoruz. btnBitmap[i, j] = new Bitmap(bmps[i, j], new Size(100, 100)); Button button = this.Controls.Find("button" + index, true).FirstOrDefault() as Button; button.Image = (Image)btnBitmap[i, j]; button.Visible = false; g.Dispose(); } } //saveImages(btnBitmap); }
private void frmMenu_Load(object sender, EventArgs e) { btnPlay.FlatAppearance.MouseDownBackColor = Color.Transparent; btnPlay.FlatAppearance.MouseOverBackColor = Color.Transparent; btnOptions.FlatAppearance.MouseDownBackColor = Color.Transparent; btnOptions.FlatAppearance.MouseOverBackColor = Color.Transparent; btnScore.FlatAppearance.MouseDownBackColor = Color.Transparent; btnScore.FlatAppearance.MouseOverBackColor = Color.Transparent; btnOut.FlatAppearance.MouseDownBackColor = Color.Transparent; btnOut.FlatAppearance.MouseOverBackColor = Color.Transparent; bmpArray = new Bitmap[size, size]; Bitmap resizedImage = new Bitmap(imageToUse, new Size(300, 300)); bmpArray = new Bitmap[size, size]; int tileSize = (int)Math.Floor((float)resizedImage.Width / size); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { Rectangle cloneRect = new Rectangle(tileSize * x, tileSize * y, tileSize, tileSize); System.Drawing.Imaging.PixelFormat format = resizedImage.PixelFormat; Bitmap tile = resizedImage.Clone(cloneRect, format); bmpArray[x, y] = tile; } } }
public void DisplayCommodityResults(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName) { if (InvokeRequired) { Invoke(new DisplayCommodityResultsDelegate(DisplayCommodityResults), s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName); return; } if (_commodityTexts != null && _correctionColumn < _commodityTexts.GetLength(1)) // there is an existingClassification screenshot being processed... { _screenshotResultsBuffer.Add(new ScreeenshotResults { originalBitmapConfidences = originalBitmapConfidences, originalBitmaps = originalBitmaps, s = s, rowIds = rowIds, screenshotName = screenshotName }); ScreenshotsQueued("(" + (_screenshotResultsBuffer.Count + ocr.ScreenshotBuffer.Count + _preOcrBuffer.Count) + " queued)"); return; } if (originalBitmaps.GetLength(0) != 0) { BeginCorrectingScreenshot(s, originalBitmaps, originalBitmapConfidences, rowIds, screenshotName); } else { tbCommoditiesOcrOutput.Text = "No rows found..."; } }
private Color GetPixel(Bitmap[,] imageArray, float x, float z) { int pixelX = (int)((x / HEX_WIDTH) * (float)IMAGE_WIDTH); int pixelZ = (int)((z / HEX_WIDTH) * (float)IMAGE_HEIGHT + (HEX_WIDTH - HEX_HEIGHT) / 2f); return(imageArray[pixelX / 256, pixelZ / 256].GetPixel(pixelX % 256, 255 - pixelZ % 256)); }
//Load the icons private void loadIcons() { int byteCount = 0; //Clear existing data iconData = new Bitmap[15, 3]; //Cycle through each slot for (int slotNumber = 0; slotNumber < 15; slotNumber++) { //Each save has 3 icons (some are data but those will not be shown) for (int iconNumber = 0; iconNumber < 3; iconNumber++) { iconData[slotNumber, iconNumber] = new Bitmap(16, 16); byteCount = 128 + (128 * iconNumber); for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x += 2) { iconData[slotNumber, iconNumber].SetPixel(x, y, iconPalette[slotNumber, saveData[slotNumber, byteCount] & 0xF]); iconData[slotNumber, iconNumber].SetPixel(x + 1, y, iconPalette[slotNumber, saveData[slotNumber, byteCount] >> 4]); byteCount++; } } } } }
private void Shuffle(Bitmap[,] array, int width, int height) { Bitmap[] oneDim = new Bitmap[width * height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { oneDim[i * height + j] = array[i, j]; } } Random rng = new Random(); int n = oneDim.Count(); while (n > 1) { n--; int k = rng.Next(n + 1); Bitmap value = oneDim[k]; oneDim[k] = oneDim[n]; oneDim[n] = value; } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { array[i, j] = oneDim[i * height + j]; } } }
private void LoadIcons() { IconData = new Bitmap[MemoryCardSlots, 3]; for (var slotIndex = 0; slotIndex < MemoryCardSlots; slotIndex++) { for (var iconIndex = 0; iconIndex < 3; iconIndex++) { IconData[slotIndex, iconIndex] = new Bitmap(IconDimensions, IconDimensions); var byteIndex = SlotHeaderLength + SlotHeaderLength * iconIndex; for (var yPixel = 0; yPixel < IconDimensions; yPixel++) { for (var xPixel = 0; xPixel < IconDimensions; xPixel += 2) { IconData[slotIndex, iconIndex].SetPixel(xPixel, yPixel, IconPalette[slotIndex, SaveData[slotIndex, byteIndex] & 0xF]); IconData[slotIndex, iconIndex].SetPixel(xPixel + 1, yPixel, IconPalette[slotIndex, SaveData[slotIndex, byteIndex] >> 4]); byteIndex++; } } } } }
public static Bitmap[,] ResizeAll(this Bitmap[,] bmps, int width, int height) { if (bmps.IsNullOrEmpty() || width <= 0 || height <= 0) { return(null); } int xParts = bmps.Width(); int yParts = bmps.Height(); Bitmap[,] result = new Bitmap[xParts, yParts]; int x = 0, y; for (; x < xParts; x++) { for (y = 0; y < yParts; y++) { if (bmps[x, y] != null) { result[x, y] = new Bitmap(bmps[x, y], width, height); } } } return(result); }
public void InitializeImage() { this.images = new Bitmap[7, 4]; this.images[0, 0] = ResizeImage(Properties.Resources.bug1, 50, 50); this.images[0, 1] = ResizeImage(Properties.Resources.bug2, 50, 50); this.images[0, 2] = ResizeImage(Properties.Resources.bug3, 50, 50); this.images[0, 3] = ResizeImage(Properties.Resources.bug4, 50, 50); this.images[1, 0] = ResizeImage(Properties.Resources.flyingsaucer1, 50, 50); this.images[1, 1] = ResizeImage(Properties.Resources.flyingsaucer2, 50, 50); this.images[1, 2] = ResizeImage(Properties.Resources.flyingsaucer3, 50, 50); this.images[1, 3] = ResizeImage(Properties.Resources.flyingsaucer4, 50, 50); this.images[2, 0] = ResizeImage(Properties.Resources.satellite1, 50, 50); this.images[2, 1] = ResizeImage(Properties.Resources.satellite2, 50, 50); this.images[2, 2] = ResizeImage(Properties.Resources.satellite3, 50, 50); this.images[2, 3] = ResizeImage(Properties.Resources.satellite4, 50, 50); this.images[3, 0] = ResizeImage(Properties.Resources.spaceship1, 50, 50); this.images[3, 1] = ResizeImage(Properties.Resources.spaceship2, 50, 50); this.images[3, 2] = ResizeImage(Properties.Resources.spaceship3, 50, 50); this.images[3, 3] = ResizeImage(Properties.Resources.spaceship4, 50, 50); this.images[4, 0] = ResizeImage(Properties.Resources.star1, 50, 50); this.images[4, 1] = ResizeImage(Properties.Resources.star2, 50, 50); this.images[4, 2] = ResizeImage(Properties.Resources.star3, 50, 50); this.images[4, 3] = ResizeImage(Properties.Resources.star4, 50, 50); this.images[5, 0] = ResizeImage(Properties.Resources.watchit1, 50, 50); this.images[5, 1] = ResizeImage(Properties.Resources.watchit2, 50, 50); this.images[5, 2] = ResizeImage(Properties.Resources.watchit3, 50, 50); this.images[5, 3] = ResizeImage(Properties.Resources.watchit4, 50, 50); this.images[6, 0] = ResizeImage(Properties.Resources.player, 50, 50); this.IGameService = new GameService(this.images); }
/// <summary> /// Creates and resizes an image array of pacman sprites /// </summary> public void InitialiseImageArray() { int nPossibleDirections = Enum.GetNames(typeof(Direction)).Length; image = new Bitmap[nPossibleDirections, ANIMATION_FRAMES]; //loads pacman images into image array for (int columns = 0; columns < nPossibleDirections; columns++) { string[] directionName = Enum.GetNames(typeof(Direction)); image[columns, 0] = new Bitmap("PacManSprites/pacmanOrange.png"); for (int rows = 1; rows < ANIMATION_FRAMES; rows++) { string imageLocation = "PacManSprites/pacmanOrange" + directionName[columns] + rows + ".png"; image[columns, rows] = new Bitmap(imageLocation); } } //makes all the images in the ghost image array the same size. for (int columns = 0; columns < image.GetLength(0); columns++) { for (int rows = 0; rows < image.GetLength(1); rows++) { Bitmap nicelySizedBitmap = new Bitmap(image[columns, rows], IMAGE_SIZE, IMAGE_SIZE); image[columns, rows] = nicelySizedBitmap; //makes the background of images transparent. Decides on the colour to make transparent based on top left pixel of image. Color transparentColour = image[columns, rows].GetPixel(0, 0); image[columns, rows].MakeTransparent(transparentColour); } } }
/// <summary> /// Constructor - Loads images from disk files. /// </summary> static Images() { // Load coin images. heads = LoadImage("Coins", "Heads150"); tails = LoadImage("Coins", "Tails150"); // Load card images. backOfCardImage = Images.LoadImage("Cards", "CardBack_Red"); cardImages = new Bitmap[CardPile.NUM_SUITS, CardPile.NUM_CARDS_PER_SUIT]; for (Suit suit = Suit.Clubs; suit <= Suit.Spades; suit++) { for (FaceValue faceValue = FaceValue.Two; faceValue <= FaceValue.Ace; faceValue++) { Card card = new Card(suit, faceValue); string cardImageName = GetCardImageName(card); cardImages[(int)card.GetSuit(), (int)card.GetFaceValue()] = LoadImage("Cards", cardImageName); } } //end for ( Suit suit ... //Load die images dieImages = new Bitmap[7]; for (int i = 1; i < dieImages.Length; i++) { string dieImageName = "Face_"; dieImageName = dieImageName + i; dieImages[i] = LoadImage("Dice", dieImageName); } }//end Images
public SpecksForm() { InitializeComponent(); openFileDialog1.Filter = "Image Files (*.bmp;*.jpg;*.png)|*.bmp;*.jpg;*.png"; imagePieces = new Bitmap[size, size]; buttons = new Button[size, size]; } // SpecksForm
private void load_images() { greendo = new Bitmap(Bitmap.FromFile("..\\..\\vproekt_data\\greendo\\greendo.png")); cast_imgs = new Bitmap[4, 6]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 6; j++) { cast_imgs[i, j] = new Bitmap(Bitmap.FromFile("..\\..\\vproekt_data\\greendo\\casting\\" + i.ToString() + "\\" + j.ToString() + ".png")); } } Rectangle r = get_bounding_rectangle(); spells = new Spell[3]; spells[0] = new Projectile_Spell("..\\..\\vproekt_data\\greendo\\spells\\spell0", 8); Spell_Fixer sf = new Spell_Fixer(new Point(bounding_rectangle.Width / 3, 0), new Point(bounding_rectangle.Width / 3, 20), new Point(10, +20), new Point(bounding_rectangle.Width / 2 + 20, 20)); spells[0].sfix = sf; sf.right = new Point(bounding_rectangle.Width - 20, 10); sf.left = new Point(20, 10); spells[1] = new Non_Projectile_Spell("..\\..\\vproekt_data\\greendo\\spells\\spell1", 6); spells[1].sfix = sf; spells[2] = new Projectile_Spell("..\\..\\vproekt_data\\greendo\\spells\\spell2", 6); spells[2].sfix = sf; }
/// <summary> /// Initializes a new instance of the <see cref="Tiles"/> class. /// </summary> /// <param name="zoom">zoom</param> /// <param name="bitmaps">An array of bitmaps.</param> /// <param name="topLeftTile">The top left tile.</param> /// <param name="bottomRightTile">The bottom right tile.</param> public Tiles(int zoom, Bitmap[,] bitmaps, Envelope topLeftTile, Envelope bottomRightTile) { Zoom = zoom; BottomRightTile = bottomRightTile; TopLeftTile = topLeftTile; Bitmaps = bitmaps; }
private void ButtonAutomaticAssemblyPuzzle_Click(object sender, EventArgs e) { // Array for puzzles with the lowest difference for each position Bitmap[,] bestChoisesForPuzzle = PuzzleSolver.GetBestPuzzleImage(listOfShuffledImages, numberOfRows, numberOfColumns); // List for swapping puzlles above and current in a game List <Bitmap> mysteryBoxesBitmaps = new List <Bitmap>(countOfFragments); for (int i = 0; i < bestChoisesForPuzzle.GetLength(0); i++) { for (int j = 0; j < bestChoisesForPuzzle.GetLength(1); j++) { mysteryBoxesBitmaps.Add(bestChoisesForPuzzle[i, j]); } } for (int i = 0; i < countOfFragments; i++) { mysteryBoxes[i].Image = mysteryBoxesBitmaps[i]; mysteryBoxes[i].ImageIndex = i; } // Event for removing borders buttonCheck.PerformClick(); buttonCheck.Enabled = false; }
// Return a bitmap based on cell, do not colorize public Bitmap GetGamePieceBitmap(int cellx, int celly) { if (_cells == null) { // break up the bitmap into cells Bitmap copied = new Bitmap(MasterBitmap.Width, MasterBitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(copied); using (g) { g.DrawImage(MasterBitmap, new Rectangle(0, 0, MasterBitmap.Width, MasterBitmap.Height)); } _cells = new Bitmap[CellsX, CellsY]; for (int y = 0; y < CellsY; y++) { for (int x = 0; x < CellsX; x++) { Bitmap cellBitmap = new Bitmap(CellWidth, CellHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics cellGraphics = Graphics.FromImage(cellBitmap); using (cellGraphics) { cellGraphics.DrawImage(copied, 0, 0, new Rectangle(CellWidth * x, CellHeight * y, CellWidth, CellHeight), GraphicsUnit.Pixel); } _cells[x, y] = cellBitmap; } } } return(_cells[cellx, celly]); }
private void btnStart_Click(object sender, EventArgs e) { Image temp = Image.FromFile(@"D:\My projects\Puzzle\PuzzleWF\Image\brain.jpg");; // берем картинку или Image.FromFile("D:\\123.png"); int count = GetCountRectangulars(temp, 200, 200); Bitmap[,] bmp = GetPuzzle(temp, 200, 200); // Bitmap[,] rndBmp = GetRandomValue(bmp); Bitmap[,] rndBmp = FisherYastes(bmp); pictureBox1.Image = rndBmp[0, 0]; pictureBox2.Image = rndBmp[0, 1]; pictureBox3.Image = rndBmp[0, 2]; pictureBox4.Image = rndBmp[1, 0]; pictureBox5.Image = rndBmp[1, 1]; pictureBox6.Image = rndBmp[1, 2]; bool checkImage = CheckImage(bmp, rndBmp); MessageBox.Show(checkImage.ToString()); //Bitmap src = new Bitmap(temp, pictureBox1.Width, pictureBox1.Height); //// Задаем нужную область вырезания (отсчет с верхнего левого угла) //Rectangle rect = new Rectangle(new Point(0, 0), new Size(pictureBox1.Width / 2, pictureBox1.Height / 2)); //// передаем в нашу функцию //Bitmap CuttedImage = CutImage(src, rect); //// результат изображение передаем на форму //pictureBox1.Image = CuttedImage; }
public Wall(string name, string price, string desc, Bitmap[,] rotsByLods, GraphicsDevice gd, string spriteName) { myWallName = name; myWallDesc = desc; myWallPrice = price; mySpriteName = spriteName; myWallRotsS1 = new Texture2D[3, 4]; myGD = gd; for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { MemoryStream ms = new MemoryStream(); Microsoft.Xna.Framework.Graphics.Color[] pixels = new Microsoft.Xna.Framework.Graphics.Color[rotsByLods[i, j].Height * rotsByLods[i, j].Width]; for (int k = 0; k < rotsByLods[i, j].Height; k++) { for (int l = 0; l < rotsByLods[i, j].Width; l++) { System.Drawing.Color currentColor = rotsByLods[i, j].GetPixel(l, k); pixels[k * rotsByLods[i, j].Width + l] = new Microsoft.Xna.Framework.Graphics.Color(currentColor.R, currentColor.G, currentColor.B, currentColor.A); } } myWallRotsS1[i, j] = new Texture2D(gd, rotsByLods[i, j].Width, rotsByLods[i, j].Height); myWallRotsS1[i, j].SetData <Microsoft.Xna.Framework.Graphics.Color>(pixels); } } myWallRotsS2 = myWallRotsS1; }
public Board(int s, int gap, int offset, int yOffset, int squareSize, Bitmap[,] bmpArray, bool animationsActive, int animationSpeed, bool multiMoves) { this.multiMoves = multiMoves; this.animationSpeed = animationSpeed; size = s; if (bmpArray != null) { this.bmpArray = bmpArray; } else { this.bmpArray = new Bitmap[s, s]; } int valueI = 1; pieceArray = new Piece[s, s]; tmrTick = new Timer(); tmrTick.Tick += tmrTick_Tick; tmrTick.Interval = 1000; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (valueI == size * size) { pieceArray[j, i] = new Piece(0, j, i, this, gap, offset, yOffset, squareSize, animationsActive); } else { pieceArray[j, i] = new Piece(valueI, j, i, this, gap, offset, yOffset, squareSize, animationsActive); } valueI++; } } }
public void Mix(Bitmap[,] bmps) { var random = Shuffle(); minMove = shortestPath(random.Clone() as int[]); int a = 0; for (int i = 0; i < 4; i++) { for (int k = 0; k < 4; k++) { Button foobar = Controls["btn_P" + a] as Button; ImageConverter converter = new ImageConverter(); // tagging button with hash bytes foobar.Tag = ImageHashing(bmps[i, k]); Button foobar2 = (Button)Controls.Find("btn_P" + random[a], false)[0]; foobar2.BackgroundImage = bmps[i, k]; foobar2.BackgroundImageLayout = ImageLayout.Stretch; a++; } } ButtonControl(); if (isFinitto()) { MessageBox.Show("Score: " + score); } }
public Bitmap[,] GetBestPuzzleImage(List <Bitmap> list) { // List<int> numbers = new List<int>(GetNumbers(list)); Bitmap[,] bestChoice = null; double min = Int32.MaxValue; //for (int i = 0; i < numbers.Count; i++) //{ // int row = numbers[i]; // int col = list.Count / row; int row = (int)Math.Sqrt(list.Count); int col = row; Bitmap[,] possibleChoice = new Bitmap[row, col]; double value = GetBestCurrentVariant(list, row, col, ref possibleChoice); if (min > value) { bestChoice = (Bitmap[, ])possibleChoice.Clone(); min = value; } // } return(bestChoice); }
private static Bitmap MergeResult(Bitmap[,] results, int sx, int sy, int n) { var ix = results.GetLength(0); var iy = results.GetLength(1); int stx = 9999; int sty = 9999; for (int x = 0; x < ix; x++) { for (int y = 0; y < iy; y++) { if (results[x, y] != null) { stx = Math.Min(x, stx); sty = Math.Min(y, sty); } } } var result = new Bitmap(n * sx, n * sy); using (var g = Graphics.FromImage(result)) { for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { g.DrawImage(results[stx + x, sty + y], x * sx, y * sy); } } } return(result); }
/// <summary> /// Constructeur pour créer une personne /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="tab"></param> /// <param name="listeVisiteur"></param> /// <param name="listeDechet"></param> /// <param name="listeConcierge"></param> /// <param name="Hero"></param> public Concierge(int x, int y, Bitmap[,] tab, List <Visiteur> listeVisiteur, List <Dechet> listeDechet, List <Concierge> listeConcierge, Hero Hero) : base(x, y, tab) { _listeDechet = listeDechet; _listeConcierge = listeConcierge; _listeVisiteur = listeVisiteur; hero = Hero; }
/// <summary> /// Constructeur pour créer un rhinocéros /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="genre"></param> /// <param name="vieillesse"></param> /// <param name="etat"></param> /// <param name="tab"></param> /// <param name="type"></param> /// <param name="listeAnimal"></param> /// <param name="Hero"></param> public Rhino(int X, int Y, Genre genre, Vieillesse vieillesse, Etat etat, Bitmap[,] tab, TypeAnimal type, List <Animal> listeAnimal, Hero Hero) : base(X, Y, Genre.Male, Vieillesse.Adulte, Etat.Nourrit, tab, TypeAnimal.Rhino, listeAnimal, Hero) { _etat = etat; _genre = genre; _vieillesse = vieillesse; _type = type; tabTypeAnimal = DeterminerAnimal(TypeAnimal.Rhino); }
public TileReader(Bitmap image, int imageheight, int imagewidth, int tilesx, int tilesy) { Image = image; ImageHeight = imageheight; ImageWidth = imagewidth; TilesX = tilesx; TilesY = tilesy; Tiles = new Bitmap[TilesX, TilesY]; }
/// <summary> /// Constructeur pour créer un visiteur /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="s"></param> /// <param name="tab"></param> /// <param name="listeVisiteur"></param> /// <param name="listeConcierge"></param> /// <param name="Hero"></param> public Visiteur(int x, int y, Sexe s, Bitmap[,] tab, List <Visiteur> listeVisiteur, List <Concierge> listeConcierge, Hero Hero) : base(x, y, tab) { _sexe = s; nom = listeNoms[GenererNom()]; tabOrientation = DeterminerVisiteur(); _listeConcierge = listeConcierge; _listeVisiteur = listeVisiteur; hero = Hero; }
public Game(Bitmap[,] bitmaps) { score = 0; livesLeft = 2; wave = 0; framesSkipped = 0; this.bitmaps = bitmaps; this.CreateInvaders(); }
public static void ArrayHistogramValues(Bitmap[,] BitmapMatrix, int[, ][] AllShades, int RowCount, int ColCount) { for (int i = 0; i < RowCount; i++) { for (int j = 0; j < ColCount; j++) { HistogramValues(BitmapMatrix[i, j], out AllShades[i, j]); } } }
// Parçalara ayrıdığımız resmi tek tek dosyaya kaydeder. private void saveImages(Bitmap[,] bmp) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { int index = (i * 4 + j) + 1; bmp[i, j].Save(@"C:\Users\Furkan\Desktop\Puzzle\button" + index + ".jpg", ImageFormat.Jpeg); } } }
private static void ReconstructFrom(Bitmap[,] result, List <EdgeTemplate> templates, int x, int y, EdgeCollection edges) { var current = result[x, y]; edges.RemoveBySource(current); while (TryReconstructFrom(result, templates, x, y, edges)) { ; } }
/// <summary> /// Constructor - Loads images from disk files. /// </summary> static Images() { // Load card images. backOfCardImage = Images.LoadImage("Cards", "CardBack_Red"); cardImages = new Bitmap[CardPile.NUM_SUITS, CardPile.NUM_CARDS_PER_SUIT]; for (Suit suit = Suit.Clubs; suit <= Suit.Spades; suit++) { for (FaceValue faceValue = FaceValue.Two; faceValue <= FaceValue.Ace; faceValue++) { Card card = new Card(suit, faceValue); string cardImageName = GetCardImageName(card); cardImages[(int) card.GetSuit(), (int) card.GetFaceValue()] = LoadImage("Cards", cardImageName); // } } //end for(Suit suit ... }
public WindowController(NetHackController nc) { font = new Font(FontFamily.GenericMonospace, 16, GraphicsUnit.Pixel); tilesRaw = new Bitmap(@"..\..\nhtiles.bmp"); // Hard coded for now tileSize = tilesRaw.Width / NUM_TILES_ACROSS; render = new Bitmap(tilesRaw.Width, tilesRaw.Height); this.nc = nc; tiles = new Bitmap[NUM_TILES_ACROSS, NUM_TILES_DOWN]; // Create tile array for (int col = 0; col < NUM_TILES_ACROSS; ++col) { for (int row = 0; row < NUM_TILES_DOWN; ++row) { tiles[col, row] = CopyBitmap(tilesRaw, new Rectangle(col * tileSize, row * tileSize, tileSize, tileSize)); } } }
private void BeginCorrectingScreenshot(string[,] s, Bitmap[,] originalBitmaps, float[,] originalBitmapConfidences, string[] rowIds, string screenshotName) { _commodityTexts = s; _originalBitmaps = originalBitmaps; _originalBitmapConfidences = originalBitmapConfidences; _screenshotName = screenshotName; _rowIds = rowIds; _correctionColumn = 0; _correctionRow = -1; bContinueOcr.Text = "C&ontinue"; bClearOcrOutput.Enabled = false; bEditResults.Enabled = false; tbFinalOcrOutput.Enabled = false; ContinueDisplayingResults(); }
/// <summary> /// Get movement samples from the specified image area /// </summary> /// <param name="x">Position of the upper left corner of the area on the x axis</param> /// <param name="y">Position of the upper left corner on of the area the y axis</param> /// <param name="width">Width of the area</param> /// <param name="height">Height of the area</param> /// <param name="maxCycles">Number of cycles to run</param> /// <param name="getImg">A delegate returning images to process</param> /// <param name="progEv">A delegate specifying code to run when progress of learning changes</param> /// <param name="complEv">A delegate specifying code to run when learning is complete</param> public void Learn(int x, int y, int width, int height, int maxCycles, Func<Bitmap> getImg, ProgressChangedEventHandler progEv, RunWorkerCompletedEventHandler complEv) { if (samples != null) { foreach(Bitmap b in samples) { b.Dispose(); } } ResizeBilinear resize = new ResizeBilinear(70, (int)(70 * ((float)height / width))); BackgroundWorker bw = new BackgroundWorker(); samples = new Bitmap[maxCycles, 10]; Crop cropFilter; Mirror mirror = new Mirror(false,true); HomogenityEdgeDetector edgeDetector = new HomogenityEdgeDetector(); // this allows our worker to report progress during work bw.WorkerReportsProgress = true; // what to do in the background thread bw.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { BackgroundWorker b = o as BackgroundWorker; //Bitmap img; int xSize = 0, ySize = 0; int numImages = 0; for (int learningPoints = 0; learningPoints < maxCycles; learningPoints++) { b.ReportProgress((100 / maxCycles) * learningPoints); for (int tutorialBox = 0; tutorialBox < 100; tutorialBox++) { if (tutorialBox % 10 == 0) { numImages += 1; b.ReportProgress((100 / maxCycles) * learningPoints + (tutorialBox / maxCycles)); cropFilter = new Crop(new Rectangle(x - tutorialBox, y, width, height)); //img = resize.Apply(maxBlobFilter.Apply(cropFilter.Apply(getImg()))); xSize += width; ySize += height; samples[learningPoints, tutorialBox / 10] = resize.Apply(mirror.Apply(cropFilter.Apply(getImg()))); samples[learningPoints, tutorialBox / 10].Save("sample" + tutorialBox / 10 + ".bmp"); } System.Threading.Thread.Sleep(15); } } avgSize.x = (float)xSize / numImages; avgSize.y = (float)ySize / numImages; avgAspectRatio = (float)xSize / ySize; b.ReportProgress(100); args.Result = samples; }); // what to do when progress changed (update the progress bar for example) bw.ProgressChanged += progEv; // what to do when worker completes its task (notify the user) bw.RunWorkerCompleted += complEv; bw.RunWorkerAsync(); }
private void XuLySuKien(object sender, EventArgs e) { if (cout==3)//chan su kien click khi game over { return; } if (kt==1) { return; } tg_progress.Start(); point[0].X = 0; point[0].Y = 0; point[1].X = 0; point[1].Y = 0; KimCuong kc = new KimCuong(); kc = (KimCuong)sender; kc.TrangThai = true;//trang thai dang kich hoat if (kc.SoMau == 0)//neu chua bam new game { kc.TrangThai = false; return; } if (cout == 0)//click lan dau tien { tg_kt.Stop(); bitmap = clip(hinh_cd[kc.SoMau], 20, 1); tg_cd.Start(); } if (cout == 1)//click lan thu 2 { int dem = 0; for (int i = 0; i < 8; i++)//doi cho 2 o gan nhau for (int j = 0; j < 8; j++) { if (mokimcuong.kimcuong[i, j].TrangThai == true) { if (dem == 0) { point[0].X = i;//luu 2 phan tu dang xu ly point[0].Y = j; } if (dem == 1) { point[1].X = i; point[1].Y = j; } dem++; } } if (dem == 2) { dem = 0; if (point[0].X == point[1].X && (point[0].Y == point[1].Y + 1 || point[0].Y == point[1].Y - 1)) { lan = 1; tg_kt.Start(); } if (point[0].Y == point[1].Y && (point[0].X == point[1].X + 1 || point[0].X == point[1].X - 1)) { lan = 1; tg_kt.Start(); } } foreach (KimCuong kc2 in mokimcuong.kimcuong) { kc2.TrangThai = false; XuatHinh(); } } cout++; if (cout == 2) { cout = 0; } }
public frmGameScreen(Game c,string l) { //******** BITMAPS ************************* // Instanciate backGround with the image at path l backGround = new Bitmap(Image.FromFile(l)); // Instanciate backGroundWithTanks with the same attributes as backGround backGroundWithTanks = new Bitmap(backGround); // Instanciate backGroundWithTanks with the same attributes as backGround backGroundWithTanksDetails = new Bitmap(backGround); //******* GRAPHICS OBJECTS ************************* // Graphics classes for drawing on different Bitmaps g = Graphics.FromImage(frame); b = Graphics.FromImage(backGround); e = Graphics.FromImage(explotionLayer); bgwt = Graphics.FromImage(backGroundWithTanks); bgwtad= Graphics.FromImage(backGroundWithTanksDetails); skyColor = backGround.GetPixel(1,1); //******* BRUSH OBJECTS ************************** //brushes to draw fire/explotions and to draw sky skyBrush = new SolidBrush(skyColor); fireBrush = new SolidBrush(fireColor); /* Set the sky color as the color at pixel 1,1 this means the the * game adapts to the image.*/ // creator is the game class this is contained in creator = c; //******************************************************************************************************** // DRAW OVER HEAD LABELS //******************************************************************************************************** // Create a 2D array of bitmaps for th lables (number of teams) X 4 overHeadLables = new Bitmap[creator.gameTeams.Length,4]; //******** ~~ Go Through all teams and tanks ********************************* for(int loopTeam = creator.gameTeams.Length-1; loopTeam >= 0; loopTeam --){ for(int loopTank = 3; loopTank >= 0; loopTank--){ //create a new Bitmap on the current index this.overHeadLables[loopTeam,loopTank] = new Bitmap(70,50); //set the graphis object lbltxt to reference the current Bitmap lbltxt = Graphics.FromImage(overHeadLables[loopTeam,loopTank]); //This creates a rectangle to draw a string on to lbltxt.FillRectangle(displayBrush,0,0,70,30); //Display team name above each tank lbltxt.DrawString(creator.gameTeams[loopTeam].teamName,myFont,textBrush,2,2); //Display tank name above each tank lbltxt.DrawString(creator.gameTeams[loopTeam].tanks[loopTank].name,myFont,textBrush,2,16); } } //*********************************************************************************************************** // // Required for Windows Form Designer support // InitializeComponent(); }
//Load the icons private void loadIcons() { int byteCount = 0; //Clear existing data iconData = new Bitmap[15,3]; //Cycle through each slot for (int slotNumber = 0; slotNumber < 15; slotNumber++) { //Each save has 3 icons (some are data but those will not be shown) for (int iconNumber = 0; iconNumber < 3; iconNumber++) { iconData[slotNumber, iconNumber] = new Bitmap(16, 16); byteCount = 128 + ( 128 * iconNumber); for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x += 2) { iconData[slotNumber, iconNumber].SetPixel(x, y, iconPalette[slotNumber, saveData[slotNumber, byteCount] & 0xF]); iconData[slotNumber, iconNumber].SetPixel(x + 1, y, iconPalette[slotNumber, saveData[slotNumber, byteCount] >> 4]); byteCount++; } } } } }