Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Graphic editing...


Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2004, 09:07 PM
Skipppyg Skipppyg is offline
Newcomer
 
Join Date: May 2004
Posts: 3
Default 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??
Reply With Quote
  #2  
Old 05-05-2004, 10:04 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

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.
Reply With Quote
  #3  
Old 05-06-2004, 01:53 AM
finneus finneus is offline
Junior Contributor
 
Join Date: Dec 2002
Posts: 316
Default

???
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.
Reply With Quote
  #4  
Old 05-06-2004, 06:56 PM
Skipppyg Skipppyg is offline
Newcomer
 
Join Date: May 2004
Posts: 3
Default

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.
Reply With Quote
  #5  
Old 05-06-2004, 08:11 PM
Gilad_r's Avatar
Gilad_r Gilad_r is offline
Senior Contributor
 
Join Date: Mar 2004
Posts: 851
Default

do it exactly like passel explained, by using the PaintPicture method of the second picturebox...
__________________
I♥Hooks
Reply With Quote
  #6  
Old 05-06-2004, 08:13 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

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.
Reply With Quote
  #7  
Old 05-06-2004, 08:51 PM
Gilad_r's Avatar
Gilad_r Gilad_r is offline
Senior Contributor
 
Join Date: Mar 2004
Posts: 851
Default

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
Reply With Quote
  #8  
Old 05-06-2004, 09:10 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial on Editing, Inserting and Displaying data using Datasets Denaes .NET Database and Reporting 0 03-16-2004 12:02 AM
how to change colors in graphic in VB 6 ??? Patxi Interface and Graphics 4 02-20-2004 01:15 PM
Editing metafile jojo36 Interface and Graphics 8 10-23-2003 06:50 AM
Custom graphic buttons wolfy1818 Interface and Graphics 2 10-14-2003 08:10 PM
Loading and re-sizing graphic peacasso General 6 04-13-2002 11:10 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->