Put image on top of this rectangle..

eramgarden

Well-known member
Joined
Mar 8, 2004
Messages
579
I want to create a canvas/rectangualr background, 500x700 and then put my image on top of the canvas

This is what I have but i only get a white rectangle with the font and NO IMAGE on top of it..

what am I missing?

Code:
Dim strFileToConvert As String
         strFileToConvert = "C:\source1.Tif"
        Initialize the bitmap object by supplying the image file path
        Dim b As New Bitmap(strFileToConvert)

        Dim g As Graphics = Graphics.FromImage(b)

  [b]      Dim rect = New Rectangle(0, 0, 500, 700)[/b]
        Dim bgBrush = New SolidBrush(System.Drawing.Color.White)

      [b]  g.FillRectangle(bgBrush, rect)[/b]

        Dim bold As Font = New Font("Times New Roman", 14, FontStyle.Regular)
     
     [b]   g.DrawString("Copyright
 
That happen because you are drawing the white rectangle over your image. You are creating a bitmpa object from the image file and then drawing on it. Instead, create a new Bitmap object but not from a file but rather 700x500 size like you want, then create Graphics object from that. Now use the DrawImage method of the Graphics object to draw another Bitmap object you declared which contains your image.
Code:
 Dim back As New Bitmap(700,500) create bitmap with the size you want
 Dim gr As Graphics = Graphics.FromImage(back) get graphics for it
 Dim img As New Bitmap("file path") load your image
 gr.FillRectangle(New SolidBrush(Color.White), New Rectangle(0,0,700,500)) fill the background
 gr.DrawImage(img, xpos, ypos) draw the image at specified position
 draw whatever else you need .... 
 back.Save("file path") save it
 img.Dispose() dont forget to dispose!
 back.Dispose()
 
Back
Top