Visual Basic??
Different Community:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
VB2020
I created a bitmap and I want to insert pictures into the image of the first bitmap.
Everything seems to be working. I load the first bitmap and I can draw on it. If I load the second bitmap and i can show it without a problem.
But if I use DrawImage, the inserted bitmap seems to be scaled.
When I do not load the file, but I open the bitmap to be inserted, "select all" and "copy" it to the clipboard, an I use Clipboard.GetImage then the inserted bitmap is not scaled, and it's using the original physical size, as it should be.
DrawImage says it will, but it's not doeing what it says.
Why is it scaling?
I have some code to test it, a form with a picturebox size 750, 665 and 4 buttons (using VB 2020)
All you have to do is giving the path where he can find the picture...
Imports System.IO
Public Class Form1
Dim bg1 As Bitmap
Dim bg2 As Bitmap
Dim Brush1 As Brush
Dim Brush2 As Brush
Dim font1 As Font
Dim grf As Graphics
Dim testfile1 As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Give the path of the picture you want to use (.bmp file)
' The picturebox1 is set to 750,665 p, best is using a picture with a smaller size...
testfile1 = Application.StartupPath + "\openbaar.bmp"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Open bg1 and draw a rectangle, 10 pixels from the sides
bg1 = New Bitmap(750, 665)
grf = Graphics.FromImage(bg1)
Brush1 = New SolidBrush(Color.Green)
grf.FillRectangle(Brush1, 10, 10, 730, 645)
PictureBox1.Image = bg1
PictureBox1.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' Load the bitmap in bg2 and show bitmap
If File.Exists(testfile1) Then
bg2 = New Bitmap(testfile1)
End If
PictureBox1.Image = bg2
PictureBox1.Show()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' Open bg1 and draw a rectangle, 10 pixels from the sides
bg1 = New Bitmap(750, 665)
grf = Graphics.FromImage(bg1)
Brush1 = New SolidBrush(Color.Green)
grf.FillRectangle(Brush1, 10, 10, 730, 645)
' Load the bitmap in bg2
If File.Exists(testfile1) Then
bg2 = New Bitmap(testfile1)
End If
' testbitmap on top and show bitmap
grf.DrawImage(bg2, 1, 1)
PictureBox1.Image = bg1
PictureBox1.Show()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' Open bg1 and draw a rectangle, 10 pixels from the sides
bg1 = New Bitmap(750, 665)
grf = Graphics.FromImage(bg1)
Brush1 = New SolidBrush(Color.Green)
Brush2 = New SolidBrush(Color.White)
font1 = New Font("Verdana", 12)
grf.FillRectangle(Brush1, 10, 10, 730, 645)
'Not longer "loading" the bitmap in bg2, instead getting the
'Image From the clipboard in bg2. Open with paint And "select all" and copy it
'to the clipboard (before pushing this button)
If Clipboard.ContainsImage Then
bg2 = Clipboard.GetImage()
grf.DrawImage(bg2, 1, 1)
Else
grf.DrawString("Clipboard is empty", font1, Brush2, 13, 13)
End If
PictureBox1.Image = bg1
PictureBox1.Show()
End Sub
End Class
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.