Results 1 to 11 of 11

Thread: Changing image shape in vb.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Changing image shape in vb.net

    Hi,

    I want to be able to take a flat image and do this with it in my program:



    I think I know a logical way of doing it but don't know how to..

    - create abitmap as bitmap
    - load image into abitmap (in this example image is 60px width x 40px height)
    - make new bbitmap as bitmap
    - bbitmap is created to a size for example 10px x 40px
    - load left section of abitmap into bbitmap so in affect now split the image into two
    - change top-right and bottom-right points to lower and higher respectively on abitmap
    - change top-left and bottom-left points to lower and higher respectively
    - create finalbitmap as bitmap
    - draw abitmap and bbitmap on finalbitmap to put them together and make one 3D image
    - now use the .mypen tool to draw the line where abitmap and bbitmap ajoins

    But..
    how do I change the points?
    how do I load only PART of an image from abitmap into bbitmap?

    Hope this makes sense?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Changing image shape in vb.net

    an image is always rectangular, although you can make part of it transparent. you could recreate that effect with the picturebox's region property + draw the white lines on the fininshed image.

    if you upload the original image i'll have a try

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Changing image shape in vb.net

    I have attached a GIF file of the original flat image.

    The only problem with the transparent line is a chunk of the image will disappear. Everywhere I read seems to be in C#.
    Attached Images Attached Images  

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Changing image shape in vb.net

    Whilst on the topic of imagery. I also want to rotate an image about 15 degrees.

    I tried:

    image.RotateFlip(15)

    But get the error:

    "Parameter is not valid."

    Can't seem to find a decent article on this anywhere. Any ideas where I am going wrong?

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Changing image shape in vb.net

    You can only rotate 90, 180 or 270. I was disappointed.
    Code:
    image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone)
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Changing image shape in vb.net

    You are looking at doing this in an easy way. That may not be possible, and even if it is, it might not be ideal. One alternative would be to draw a mesh and texturemap the image onto the mesh. That would be 3D graphics, probably using DirectX....and that's as far as I know, cause I suck at graphics. Still, that is how people make things like spinning cubes with images on them, objects in 3D games (where the object is VASTLY more complex than a simple cube), and so forth. It's a whole different area, though.
    My usual boring signature: Nothing

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Changing image shape in vb.net

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim img As New Bitmap("C:\Users\Paul\Desktop\3107017.png")
    5.         Dim gr As Graphics = Graphics.FromImage(img)
    6.         gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    7.         gr.FillPolygon(Brushes.White, New PointF() {New PointF(0, 0), New PointF(img.Width - 1, 0), New PointF(img.Width - 1, 60), New PointF(29, 10), New PointF(0, 37)})
    8.         gr.FillPolygon(Brushes.Magenta, New PointF() {New PointF(0, 0), New PointF(img.Width - 1, 0), New PointF(img.Width - 1, 55), New PointF(29, 5), New PointF(0, 32)})
    9.         gr.FillPolygon(Brushes.White, New PointF() {New PointF(0, img.Height - 1), New PointF(img.Width - 1, img.Height - 1), New PointF(img.Width - 1, img.Height - 46), New PointF(29, img.Height - 11), New PointF(0, img.Height - 26)})
    10.         gr.FillPolygon(Brushes.Magenta, New PointF() {New PointF(0, img.Height - 1), New PointF(img.Width - 1, img.Height - 1), New PointF(img.Width - 1, img.Height - 41), New PointF(29, img.Height - 6), New PointF(0, img.Height - 21)})
    11.         gr.DrawLine(New Pen(Color.White, 5), 2, 32, 2, img.Height - 21)
    12.         gr.DrawLine(Pens.White, 29, 10, 29, img.Height - 10)
    13.         gr.DrawLine(New Pen(Color.White, 3), img.Width - 3, 60, img.Width - 3, img.Height - 45)
    14.         img.MakeTransparent(Color.Magenta)
    15.  
    16.         Dim path As New Drawing.Drawing2D.GraphicsPath
    17.         path.AddPolygon(New PointF() {New PointF(img.Width - 1, img.Height - 41), New PointF(img.Width - 1, 55), New PointF(29, 5), New PointF(0, 32), New PointF(0, img.Height - 21), New PointF(29, img.Height - 6)})
    18.         PictureBox1.Image = img
    19.         PictureBox1.Region = New Region(path)
    20.     End Sub
    21.  
    22. End Class

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Changing image shape in vb.net

    as shaggy said there are better ways of doing this. my effort is just a 3d illusion

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Changing image shape in vb.net

    Quote Originally Posted by .paul. View Post
    as shaggy said there are better ways of doing this. my effort is just a 3d illusion
    Illusions can be better than reality if they are suitable. I remember reading in a graphics book about the final space battle in the third installment of the first Star Wars trilogy (was that Return of the Jedi?). The battle was some big free for all around the partially completed death star. Apparently, if you freeze one of the scenes and look at all the ships, one of them looks like a sneaker....because it IS a sneaker. People don't generally notice that while watching the movie, because they see what they expect to see.
    My usual boring signature: Nothing

  10. #10
    Addicted Member vb_ftw's Avatar
    Join Date
    Dec 2010
    Posts
    139

    Re: Changing image shape in vb.net

    well i guess arcon's a lucky guy,
    i've been trying to do this too..lol
    well here's my code much like .paul.'s
    no time for bg shadow
    vb Code:
    1. If path = "" Then
    2.             Exit Sub
    3.         End If
    4.         Dim a As New Bitmap(path) 'load file
    5.        
    6.         Dim x As Integer = a.Width 'get loaded file's width
    7.         Dim y As Integer = a.Height
    8.         Dim sidex As Integer = Math.Ceiling(x * 0.07) 'get 7% of x
    9.         Dim restx As Integer = x - sidex            'image size - 7%
    10.  
    11.  
    12.        
    13.      
    14.         Dim Polygon_pts() As Point = { _
    15.             New Point(20, 20), _
    16.             New Point(sidex, 10), _
    17.             New Point(restx, 60), _
    18.             New Point(restx, y - 60), _
    19.             New Point(sidex, y), _
    20.             New Point(20, y - 30), _
    21.             New Point(20, 20)}
    22.  
    23.  
    24.         Dim Polygon_shadow_pts() As Point = { _
    25.              New Point(18, 18), _
    26.              New Point(sidex, 8), _
    27.              New Point(restx + 2, 58), _
    28.              New Point(restx + 2, y - 58), _
    29.              New Point(sidex, y + 2), _
    30.              New Point(18, y - 28), _
    31.              New Point(18, 18)}
    32.  
    33.         Dim try_poly As New Bitmap(x + 10, y + 10) 'create new bitmap for final image
    34.         Dim g As Graphics = Graphics.FromImage(try_poly) 'create a graphics object
    35.  
    36.         'set modes for better quality
    37.         g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    38.         g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
    39.         g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    40.  
    41.  
    42.         g.FillPolygon(Brushes.White, Polygon_shadow_pts) 'draw background polygon
    43.         g.FillPolygon(New TextureBrush(a), Polygon_pts) 'draw polygon and texture image
    44.         g.DrawLine(New Pen(Color.White, 2), sidex, 10, sidex, y) 'draw perspective line
    45.  
    46.         'save
    47.         try_poly.Save(My.Computer.FileSystem.SpecialDirectories.Desktop & "\AA.png", _
    48.                       System.Drawing.Imaging.ImageFormat.Png)
    49.  
    50.  
    51.         'display the image in the picture box
    52.         PictureBox1.Image = try_poly

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Changing image shape in vb.net

    Sorry for the delay. Only just read the new posts.

    It works excellent. All the info was great. You guys are AMAZING

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width