 |

05-05-2004, 09:07 PM
|
|
Newcomer
|
|
Join Date: May 2004
Posts: 3
|
|
Graphic editing...
|
Ok, here's what I need to know how to do. I want to make a program that will take a picture of any size that you pick, take this picture from your hard drive into the program, chops the picture into 16 pixel by 16 pixel image sand save each little cut up square into it's own ".BMP" file. Does anyone have any pointers on how to go about this? I can see the saving part, using an array, moving it possibly into an Imagebox and saving it from there....but how would one import the pic into the program, and most importantly chop it into it's manageable chunks??
|
|

05-05-2004, 10:04 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
|
I guess you'll have to decide what you want to do if the picture isn't a multiple of 16 pixels.
For simplicity, I would have the Form's Scalemode set to Pixels, so the pictureboxes sizes are given in pixels.
I would use two pictureboxes, again Scalemodes set to Pixels, with no border so that the width and scalewidth are the same.
Set one to AutoSize so that it's image size will match the picture size.
Set both pictures AutoRedraw to true, the picturesboxes don't have to be visible.
Use LoadPicture to load the picture into the Autosizing Picturebox.
You will need a loop to loop through all the pieces.
Then use the other pictureboxes PaintPicture method to copy a 16 by 16 pixel portion
of the big picture into the 16x16 box.
Then use SavePicture with the 16x16 boxes .image (not .picture) property to save the
bitmap.
You will probably want to create a name, using the X and Y index of the portion of the big picture to create unique file names.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

05-06-2004, 01:53 AM
|
|
Junior Contributor
|
|
Join Date: Dec 2002
Posts: 316
|
|
|
???
640 X 480 image
480 X 640 image
or even more unsquare???
to 16 X 16 pixels = bad image....
use point to find the color of each pixel & a flexgrid to display the points.
I've used this to debug my karaoke system, works great, but really slow.
|
|

05-06-2004, 06:56 PM
|
|
Newcomer
|
|
Join Date: May 2004
Posts: 3
|
|
|
Ok that sounds like it isn't too difficult. My only real problem here is this:
How do I go about seperating the 16x16 piece from the whole image? I know how it will loop and whatnot, and I'm not looking for speed. Is there really any other way then to copy each individual pixel?! An easier way would be much appreciated, and I'm only caught on this particular snag.
Thanks again.
|
|

05-06-2004, 08:11 PM
|
 |
Senior Contributor
|
|
Join Date: Mar 2004
Posts: 851
|
|
|
do it exactly like passel explained, by using the PaintPicture method of the second picturebox...
|
__________________
I♥Hooks
|

05-06-2004, 08:13 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
It shouldn't be that difficult.
Here's a simple example. Just put two pictureboxes and a command button on a form
and paste this code in the General Declarations section of the editor.
Change the two places where the input and output file names are specified ("c:\cac")
and give it a try.
Code:
Private Sub Command1_Click()
Dim px As Single, py As Single
Dim nx As Integer, ny As Integer, x As Integer, y As Integer
Picture1.Picture = LoadPicture("c:\cac.jpg")
nx = ((Picture1.Width + 15) \ 16) - 1 'how many tiles in X
ny = ((Picture1.Height + 15) \ 16) - 1 ' how many tiles in Y
px = 0: py = 0
For y = 0 To ny
For x = 0 To nx
filenam = "c:\cac" & Format$(x) & Format$(y) & ".bmp"
Picture2.Cls
Picture2.PaintPicture Picture1.Image, 0, 0, 16, 16, px, py, 16, 16
SavePicture Picture2.Image, filenam
px = px + 16
Next
px = 0
py = py + 16
Next
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture1.BorderStyle = vbBSNone
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture2.ScaleMode = vbPixels
Picture2.BorderStyle = vbBSNone
Picture2.AutoRedraw = True
Picture2.Width = 16
Picture2.Height = 16
Picture2.BackColor = vbBlack
End Sub
P.S. Oops, I misread your post and thought you said it sounded difficult and were looking for another method reading individual pixels. Oh well. We usually refrain from handing out code until the poster has had time to attempt a solution themselves, with some aid on sticking points. I guess you get a freebie this time.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 05-06-2004 at 08:19 PM.
|

05-06-2004, 08:51 PM
|
 |
Senior Contributor
|
|
Join Date: Mar 2004
Posts: 851
|
|
i would just change this:
Code:
Dim px As Single, py As Single
Dim nx As Integer, ny As Integer, x As Integer, y As Integer
...
nx = ((Picture1.Width + 15) \ 16) - 1 'how many tiles in X
ny = ((Picture1.Height + 15) \ 16) - 1 ' how many tiles in Y
px = 0: py = 0
For y = 0 To ny
For x = 0 To nx
...
Picture2.PaintPicture Picture1.Image, 0, 0, 16, 16, px, py, 16, 16
...
px = px + 16
...
px = 0
py = py + 16
...
to this:
Code:
Dim x As Integer
Dim y As Integer
...
For y = 0 To Picture1.Height Step 16
For x = 0 To Picture1.Width Step 16
...
Picture2.PaintPicture Picture1.Image, 0, 0, 16, 16, [B]x[/B], [B]y[/B], 16, 16
...
|
__________________
I♥Hooks
|

05-06-2004, 09:10 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
|
I would have, but since I was using the x and y in the file name I thought it would be
easier to decode the file names if the x and y were sequential rather than multiples of 16.
But I probably should have put a character like "_" between the x and y to make the output file name more decipherable, and to prevent duplicate file names, since the digits are all run together. Some pictures are clobbering others, i.e.
Row 1 column 11 is clobbered by Row 11 column 1 since the name comes out the same with my code.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Last edited by passel; 05-07-2004 at 07:45 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|