Home > Software engineering >  How to control the graphics with VB program to generate graphics pixel size
How to control the graphics with VB program to generate graphics pixel size

Time:09-19

Using VB to draw graphics, want to control the pixel size of a good graphics program how to write? For example I would like to generate the size is 799 x 1159 pixels of graphics to BMP format, to the great god for help

CodePudding user response:

In a pictureBox drawing, pictureBox scalemode set to vbPixels, height is set to 799, the width is set to 1159, save the pictureBox image is 799 x 1159,

CodePudding user response:

reference 1st floor VBToy response:
with a pictureBox drawing, pictureBox scalemode set to vbPixels, height is set to 799, the width is set to 1159, save the pictureBox image is 799 x 1159,

You do this, you never even purpose,


Scalemode affects only when "drawing" individual "primitive pixel coordinates" with "memory bitmap" "mapping relationship between image data,
Will not affect the "memory bitmap size", also won't affect the store after the image size,
And, when you change your ScaleWidth or ScaleHeight value, its ScaleMode nature becomes 0 - User (User mode);
You specify beforehand 3 - Pixel patterns have failed,
Height, width is decided to control the size, but its unit of measure is depends on its "container", rather than its own ScaleMode,

The right thing to do, it should be:
To resize the PictureBox control (can adjust when the design, also can adjust) by executing code at run time,
Let it just to make it the size of the ScaleWidth=799 pixels, ScaleHeight=1159 pixels,
Then put AutoRedraw is set to True, then on the PictureBox drawing, painting and save the Image, the Image data is a 799 x 1159 size of the bitmap,

Such as set in the design of the size of the PictureBox: assuming that controls the size of the unit of measure is "certain" default units (VB6), appearance is 3 d and with borders:
ScaleWidth to 799 pixels, then controls the Width must be 803 pixels and its Width attribute is set to 12045 (when its ScaleWidth=11985);
ScaleHeight to 1159 pixels, controls Height is 1163 pixels, his Height attribute is set to 17445 (when its ScaleHeight=17385),
11985=799 pixels, 17385=1599 pixels,
If the "just" set PicutreBox ScaleMode changes for the size of 3 - Pixel, can see its ScalWidth, ScaleHeight 799 and 1159 respectively,

CodePudding user response:

refer to the second floor Chen8013 response:
Quote: refer to 1st floor VBToy response:

In a pictureBox drawing, pictureBox scalemode set to vbPixels, height is set to 799, the width is set to 1159, save the pictureBox image is 799 x 1159,

You do this, you never even purpose,


Scalemode affects only when "drawing" individual "primitive pixel coordinates" with "memory bitmap" "mapping relationship between image data,
Will not affect the "memory bitmap size", also won't affect the store after the image size,
And, when you change your ScaleWidth or ScaleHeight value, its ScaleMode nature becomes 0 - User (User mode);
You specify beforehand 3 - Pixel patterns have failed,
Height, width is decided to control the size, but its unit of measure is depends on its "container", rather than its own ScaleMode,

The right thing to do, it should be:
To resize the PictureBox control (can adjust when the design, also can adjust) by executing code at run time,
Let it just to make it the size of the ScaleWidth=799 pixels, ScaleHeight=1159 pixels,
Then put AutoRedraw is set to True, then on the PictureBox drawing, painting and save the Image, the Image data is a 799 x 1159 size of the bitmap,

Such as set in the design of the size of the PictureBox: assuming that controls the size of the unit of measure is "certain" default units (VB6), appearance is 3 d and with borders:
ScaleWidth to 799 pixels, then controls the Width must be 803 pixels and its Width attribute is set to 12045 (when its ScaleWidth=11985);
ScaleHeight to 1159 pixels, controls Height is 1163 pixels, his Height attribute is set to 17445 (when its ScaleHeight=17385),
11985=799 pixels, 17385=1599 pixels,
If the "just" set PicutreBox ScaleMode changes for the size of 3 - Pixel, can see its ScalWidth, ScaleHeight 799 and 1159 respectively,

Is not set ScaleWidth, set the Width

CodePudding user response:

Will be placed picturebox containers such as form and picturbox scalemode set to pixels, width and height of a picturebox is placed in the need of pixels, so that you can according to the pixel drawing need to the size of the graphics,

CodePudding user response:

 SavePicture statements example 
This example USES SavePicture statement save Picture in Picture Form object attribute the graphics, want to try this example, the following code can be pasted into statement part of the Form object, and then run this case, click the Form object,

Private Sub Form_Click ()
'declare variables,
CX, Dim CY, Limit, the Radius as an Integer, Msg as String
ScaleMode=vbPixels' set the scale model to pixels,
AutoRedraw=True 'open AutoRedraw,
Width=Height and change the Width to Height matching,
CX=ScaleWidth/2 'set X position,
CY=ScaleHeight/2 'set Y position,
Limit=CX 'limited by the size of the circle,
For the Radius=0 To Limit set Radius,
'CX, Circle (CY), Radius, RGB (, Rnd, Rnd Rnd * 255 * 255 * 255)
DoEvents' transfer to other operations,
Next the Radius
Msg="Choose OK to save the graphics from this form"
Msg=Msg & amp; "To a bitmap file."
MsgBox Msg
SavePicture Image, "TEST. BMP" 'pictures will save to file,
End Sub

CodePudding user response:

reference 4 floor VBToy response:
to place the containers such as form and picturbox picturebox, scalemode set to pixels, width and height of a picturebox is placed in the need of pixels, so that you can according to the pixel drawing need to the size of the graphics,

Is my mistake,


But you set the Width and Height, its Image among "border" takes the pixel,
Only set the control to without borders, width and height of the Image can be compatible with the width and height of a control,

CodePudding user response:

1: set the picturebox scalemode to pixel
2: sets the border at the picturebox without borders
3: adjust the picturebox to the size of the size you need
4: save the file with savepicture command
  • Related