Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create bitmaps 1

Status
Not open for further replies.

FractalWalk

Technical User
Nov 18, 2002
141
US

I am pretty much a VB novice and I have never worked with graphics before but I need a way to create a bitmap from VB5. What I have is an array that contians the RBG values and XY position of every pixel in the image. How can I get this into a .bmp file format?
 
need to know: If your array's name is e.g. "MyArr()" what are his parameters?

e.g MyArr(R,G,B,X,Y) ???
 
stick a picture box on your form and inside a loop use

Code:
Picture1.PSet (x, y), myColour

then to save use

Code:
SavePicture Picture1.Image, "c:\myPicture.bmp"

its not very efficient (my test code with 1million pixels is slow as hell)

NB: for this code to work autoredraw must be set to true

If somethings hard to do, its not worth doing - Homer Simpson
 
ADoozer:

Thanks. Except for determing the size, that works.

I am totally confused on how I get this to the proper size though. I want my output to be a specific number of pixels. But the way the default properties are set it is scaling it somehow.

I played around with Scaleheight and Height properties but I don't understand what those numbers mean. How do I set the picture to be X by Y pixels? And how do I fill it with a 1:1 ratio of my dataset (i.e. 1 datapoint = 1 pixel).
 
I'm still not 100% sure what I am doing but I got it to work.

Evidently, the form can only be sized in twips. So I set it to 30k x 30k (bigger than the picture ever will be). Then for my picture control I set my scalemode to pixels. However, like the form the height property stayed in twips like the form and I couldn't get an appopriate conversion to pixels to work.

Then magically it switched to pixels (which I still don't get). So now I am OK. Since it is in pixels I can resize it on the fly to fit what I need:

Picture1.Height = vert - 1
Picture1.Width = horiz - 1
 
maybe thats a quirk of VB5??

as you say setting the picture box' scalemode to pixels should allow you to resize the interior to the amount of pixels you require (via scalewidth and scaleheight)

glad to here you got it working.

If somethings hard to do, its not worth doing - Homer Simpson
 
Follow up to my own post:

The reason I was having trouble getting pixels to work was that the PictureBox was created before I changed the form measurement to twips. Evidently VB "grandfathers" the controls so my picture box could only be measured by the form measurement at the time it was created (twips).

When I deleted the picturebox and created a new one, it used pixels as the default measurement. That is because at that time the form measurement had already been changed to pixels.

That was how it "magically" changed for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top