Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cut PNG file or any image

Cut PNG file or any image

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Just Greeky Creek
    wrote on last edited by
    #1

    :-D i have a png file which includes 20 different icon. i load it into a image variable but i have no idea how i can cut icons from there. Example Code Dim img As Image img = img.FromFile("Icons.png") 'i need an method like Getimage (x, y, Width, Height) as image dim newImg as Image newImg =img.GetImage(x, y, Width, Height) Any Idea? thanks.

    R 1 Reply Last reply
    0
    • J Just Greeky Creek

      :-D i have a png file which includes 20 different icon. i load it into a image variable but i have no idea how i can cut icons from there. Example Code Dim img As Image img = img.FromFile("Icons.png") 'i need an method like Getimage (x, y, Width, Height) as image dim newImg as Image newImg =img.GetImage(x, y, Width, Height) Any Idea? thanks.

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Your GetImage function could look like the following: Public Function Getimage(ByVal sourceImage As Image, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As Image Dim result As Bitmap = New Bitmap(width, height) Dim g As Graphics Try g = Graphics.FromImage(result) g.DrawImageUnscaled(sourceImage, -x, -y) Finally If Not g Is Nothing Then g.Dispose() End If End Try Return result End FunctionHavent tested the code but I think it should work. In general it just generates an empty Bitmap, creates a Graphics object and draws the original image at a location so that only the needed part is drawn. There are probably more efficient ways out there, but it should do fine this way for smaller images.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups