G
Guest
I need to load the screen size picture into PocketPC and show it to user.
Then I need to split this picture into array (let's say 10x10), shuffle it and show this shuffled picture to user again.
//Load Picture
inImage = new Bitmap (myFile);
Graphics tmpG = Graphics.FromImage(inImage);
tmpG.DrawImage(inImage, 0,0);
tmpG.Dispose();
tmpG = null;
//Split picture to array [10,10]
private Image [,] fieldImages;
fieldImages = new Image [10,10];
tmpSquare = this.ClientSize.Width/10;
for(int y = 0; y < 10 ; y++){
for (int x = 0; x < 10 ; x++){
Image tmpImage = new Bitmap(tmpSquare, tmpSquare);
Graphics smallG = Graphics.FromImage(tmpImage);
Rectangle tmpRect = new Rectangle (tmpSquare * x, tmpSquare * y, tmpSquare, tmpSquare);
smallG.DrawImage(inImage, 0,0, tmpRect, GraphicsUnit.Pixel);
fieldImages[x,y] = tmpImage;
tmpImage = null;
smallG.Dispose();
smallG = null;
}
}
It works, but terribly slowly. The main reason is creating (and disposing) new Image and new Graphics in for loop 10x10=100 times!
I want to ask is there a way to the same task faster? Can I split an image (take a piece of it without resizing), put it into array, and do not create new Graphics? May be there are proper API functions or other techniques? A piece of code would be welcome.
Then I need to split this picture into array (let's say 10x10), shuffle it and show this shuffled picture to user again.
//Load Picture
inImage = new Bitmap (myFile);
Graphics tmpG = Graphics.FromImage(inImage);
tmpG.DrawImage(inImage, 0,0);
tmpG.Dispose();
tmpG = null;
//Split picture to array [10,10]
private Image [,] fieldImages;
fieldImages = new Image [10,10];
tmpSquare = this.ClientSize.Width/10;
for(int y = 0; y < 10 ; y++){
for (int x = 0; x < 10 ; x++){
Image tmpImage = new Bitmap(tmpSquare, tmpSquare);
Graphics smallG = Graphics.FromImage(tmpImage);
Rectangle tmpRect = new Rectangle (tmpSquare * x, tmpSquare * y, tmpSquare, tmpSquare);
smallG.DrawImage(inImage, 0,0, tmpRect, GraphicsUnit.Pixel);
fieldImages[x,y] = tmpImage;
tmpImage = null;
smallG.Dispose();
smallG = null;
}
}
It works, but terribly slowly. The main reason is creating (and disposing) new Image and new Graphics in for loop 10x10=100 times!
I want to ask is there a way to the same task faster? Can I split an image (take a piece of it without resizing), put it into array, and do not create new Graphics? May be there are proper API functions or other techniques? A piece of code would be welcome.