Re: Resize panel image and maintain aspect ratio

From: Peter Proost (pproost_at_nospam.hotmail.com)
Date: 11/02/04


Date: Tue, 2 Nov 2004 15:59:56 +0100

Hi,

maybe this can help you, place a panel on a form and then two picturboxes in
the panel,
send the second picturebox to the back. For both pictureboxes chose dock =
fill and for
the panel anchor the top, bottom,left and right. set an image in the image
property of the second
picturebox, copy paste the code below and run the app and resize the form to
see what happens.
Don't mind about the comments in the code, they're in dutch. I know it's not
everything you asked, but it can be a start

hth Peter

<<<<<code>>>>>>

Private bmp As Bitmap
Private ptbBreedte, ptbHoogte As Integer
Private imgBr, imgHo As Integer
Private schaalH, schaalB, schaal As Double

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) _ Handles MyBase.Resize
  Try

     ptbBreedte = PictureBox1.Width
     ptbHoogte = PictureBox1.Height
     imgBr = PictureBox2.Image.Width
     imgHo = PictureBox2.Image.Height
     schaalH = ptbHoogte / imgHo
     schaalB = ptbBreedte / imgBr
     'schalen gebaseerd op wie de grootste aanpassing moet doen, de hoogte
     'of de breedte, in dit geval kan de schaal niet gebaseerd worden op de
     'breedte en hoogte van de image omdat de picturebox geresized kan
worden
     if schaalH > schaalB Then
        schaal = ptbBreedte / imgBr
     Else
        schaal = ptbHoogte / imgHo
     End If

     bmp = New Bitmap(Panel1.Width, Panel1.Height)
     Dim g As Graphics = Graphics.FromImage(bmp)
     g.Clear(Color.White)
     g.DrawImage(PictureBox2.Image, New Rectangle(5, 5, CInt(imgBr *
schaal) - 10, _ CInt(imgHo * schaal) - 10), 0, 0, PictureBox2.Image.Width,
PictureBox2.Image.Height, GraphicsUnit.Pixel)
     PictureBox1.Image = bmp
     g.Dispose()
  Catch ex As Exception
         MsgBox(ex.ToString)
  End Try
End Sub

<<<<<<<<code>>>>>>>>

"Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
news:eguvpzNwEHA.3808@TK2MSFTNGP15.phx.gbl...
> Carl,
>
> For that you need the GDI+ classes with what are all your questions in my
> opinion completly possible, however no easy stuff and therefore are
samples
> almost very special.
>
> http://msdn.microsoft.com/vbasic/atthemovies/howto/default.aspx
>
> I hope this helps?
>
> Cor
>
>
> "Carl Gilbert" <cnl@newsgroup.nospam>
>
> >
> > I am looking for either a component or technique to allow me to do the
> > following:
> >
> > * Provide a panel with a background image
> > * Resize the image to best fit the panel to maintain aspect ratio
> > * Provide white (or other color) borders at the sides or the top/bottom
> >
> > The last point would be used to allow users to resize the panel to any
> > ratio
> > whilst maintaining the images ratio.
> >
> > Regards, Carl Gilbert
> >
>
>



Relevant Pages

  • Re: Transparent label over live video stream
    ... Image property of the PictureBox for each frame I capture. ... >> This software has a form with a panel which is the preview window. ...
    (microsoft.public.dotnet.framework.drawing)
  • PictureBox with scroll bar control
    ... yes folks that is progress! ... Someone in this ng suggested just drop your picturebox into a panel ... vertically so as to only have 1 scrollbar at a time. ...
    (microsoft.public.dotnet.languages.vb)
  • Scrollbar Question
    ... I have a form containing a panel and a picturebox inside the panel. ... The form load code changes the panel size to 400x400 and the picturebox size ... the bottom part of the vertical scrollbar on the right side of the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Transparent Label
    ... the image won't stretch in a panel because there is no SizeMode property. ... > you're seeing the gray background of the Form, not the PictureBox. ... > B) Set the Parent of the Label to be the PictureBox. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Which component to use to display mathematical graphs with VB6
    ... DC (an invisible Autoredraw borderless PictureBox the same size as the ... and another small VB app which contains the Form you are displaying on ... background image and a few transparent sprites per frame), ... Private Type PointAPI ...
    (comp.lang.basic.visual.misc)

Loading