Link to home
Start Free TrialLog in
Avatar of robertstuckey
robertstuckey

asked on

PictureBox access to ImageRectange properties

I have a PictureBox named Piccy with size 256,256

I have a BMP created with bump = New Bitmap(512, 512, Drawing.Imaging.PixelFormat.Format24bppRgb) which display data using the method                     bump.SetPixel(xpos, ypos, colour) as information is gathered


and have assigned bump to piccy with piccy.Image = bump
and used piccy.SizeMode = PictureBoxSizeMode.Normal

the image shown is the upper left quadrant of the bmp image with the private piccyimagerectangle properties being
x = 0
y = 0
width = 512
height = 512

using piccy.SizeMode = PictureBoxSizeMode.StretchImage gives the complete bmp with the private piccy.imagerectangle properties being
x = 0
y = 0
width = 252
height = 252

finally using piccy.SizeMode = PictureBoxSizeMode.CenterImage gives a centred bmp with the private piccy.imagerectangle properties being
x = -130
y = -130
width = 512
height = 512

I would like to perform panning and zooming in a similar way using the private piccy.imagerectangle properties

what methods and properties do i need to modify in order to affect these properties and thereby achieve a custom panning and zooming function?

i have tried using clientrectangles, clientsize all of which fail miserably

I do not want to create clones of bitmap which would represent the zoomed/panned image, just use the original single BMP
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RonaldBiemans
RonaldBiemans

I see there is also drag and drop in there :-)
Avatar of robertstuckey

ASKER

unfortunately cloning of bitmaps would only be my last resort although your clones do rotate and zoom fine

i'm sure microsoft in their infinite wisdom must have implemented some methods or properties to allow how the .image can be user configured other than the preset PictureBoxSizeMode.Normal, .StretchImage, and .CenterImage. They must have disposed of all the good VB6 people

when i said I would like to perform panning and zooming in a similar way using the private piccy.imagerectangle properties, i meant doing it as they do it by allowing the single picturebox to link to the original image and for the display of the image to be tweaked, effectively by modifying the imagerectangle properties and not modifying the actual image and relinking it to the picturebox

its a pity its only worth 500 points

Hi robertstuckey, call me stupid, but where is the cloning.
this class handles will transform the actual bitmap

Imports System.Drawing.Image
Imports System.Drawing

Public Class MyBitmap

    Public _inputBitmap As Bitmap

    Public ReadOnly Property thebitmap() As Bitmap
        Get
            Return _inputBitmap
        End Get
    End Property

    ReadOnly Property Height() As String
        Get
            Return _inputBitmap.Height
        End Get
    End Property

    ReadOnly Property Width() As String
        Get
            Return _inputBitmap.Width
        End Get
    End Property

    Public Sub New(ByVal MyBitmap As Bitmap)
        Try
            _inputBitmap = MyBitmap
        Catch er As Exception
            Throw er
        End Try
    End Sub


    Public Function Crop(ByVal Height As String, ByVal Width As String) As Bitmap
        Dim recCrop As Rectangle
        Dim bmpCrop As Bitmap
        Dim gphCrop As Graphics
        Dim recDest As Rectangle
        Try
            recCrop = New Rectangle(0, 0, Width, Height)
            bmpCrop = New Bitmap(recCrop.Width, recCrop.Height, _inputBitmap.PixelFormat)
            gphCrop = Graphics.FromImage(bmpCrop)
            recDest = New Rectangle(0, 0, Width, Height)
            gphCrop.DrawImage(_inputBitmap, recDest, recCrop.X, recCrop.Y, recCrop.Width, _
                recCrop.Height, GraphicsUnit.Pixel)
            Return _inputBitmap
        Catch er As Exception
            Throw er
        Finally
            gphCrop.Dispose()
        End Try
    End Function

    Public Function Rotate(ByVal Flip As String) As Bitmap


        Try
            Select Case Flip
                Case "90"
                    _inputBitmap.RotateFlip(RotateFlipType.Rotate90FlipXY)
                Case "180"
                    _inputBitmap.RotateFlip(RotateFlipType.Rotate180FlipXY)
                Case "270"
                    _inputBitmap.RotateFlip(RotateFlipType.Rotate270FlipXY)
            End Select
            Return _inputBitmap

        Catch er As Exception
            Throw
        End Try

    End Function

    Public Function Resize(ByVal Height As String, ByVal Width As String)
        Dim inp As New IntPtr

        Try
            If Height > 0 And Width > 0 Then
                _inputBitmap = _inputBitmap.GetThumbnailImage(Height, Width, Nothing, inp)
            Else
                _inputBitmap = _inputBitmap
            End If
            Return _inputBitmap

        Catch er As Exception
            Throw er
        Finally
        End Try
    End Function

End Class
cloning was probably the wrong word to use

while your original routine was able to zoom and rotate the original image without cloning, it would need clones of the original bitmap in order to pan, in a similar way to how your second routines work

i was thinking of the bitmap function clone, the example given:

Dim Bump As New Bitmap(512, 512, Drawing.Imaging.PixelFormat.Format24bppRgb)
' Clone a portion of the Bitmap object.
Dim cloneRect As New RectangleF(128, 128, 256, 256)
Dim cloneBitmap As Bitmap = Bump.Clone(cloneRect, .PixelFormat.Format24bppRgb)

which would be similar to your gphCrop.DrawImage(_inputBitmap, recDest, recCrop.X, recCrop.Y, recCrop.Width, _
                recCrop.Height, GraphicsUnit.Pixel)

this in conjunction with PictureBoxSizeMode.StretchImage would give the effect i wanted with the cloneRect X and Y performing the panning and the cloneRect width and height effecting the zoom with 512,512 as 1:1, 256,256 2:1 128,128 4:1 etc

I would still ideally want to wait for a solution to modifying the picturebox properties/methods rather than the methods so far covered
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think what i was wanted is probably impossible so split points for a helpful answer

the good is only because it was not the solution i wanted