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. Image Resize and Crop, am I on the right track?

Image Resize and Crop, am I on the right track?

Scheduled Pinned Locked Moved Visual Basic
graphicscsharpasp-nethelp
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.
  • R Offline
    R Offline
    RX Maverick
    wrote on last edited by
    #1

    I'm not sure that's an appropriate title but I can't think of a better one. So far I have the image resizing with the line: imageBmp = New Bitmap(imageBmp, New Size(imageWidth, imageHeight)) To me that feels sloppy, and so far I can't figure out a nice way to make a single like way to crop, and if I do I feel it will be just as bad. Am I on the wrong track? Am I just over worrying about something simple that won't save/waste processor time/power? Would it be better for me to do both at once (resize and crop) by making a second image and using DrawImage like in the code below (currently it just crops)? imageNew As Bitmap = new Bitmap(Width, Height) imageNewGraphic As Graphics = Graphics.FromImage(imageNew) imageNewGraphic.DrawImage(imgBmp, new Rectangle(0, 0, Width, Height), X, Y, Width, Height, GraphicsUnit.Pixel) I think I explained this well, I know there are other codes out there I could copy and I know that I'm reinventing the wheel, but I find I learn better this way. I'm very know to VB.NET but have had other programing training. Also this will be output to the web via ASP.NET using imageBmp.Save(Response.OutputStream, I don't believe that matters but I wanted to mention it anyway. Thanks for any help provided.

    D 1 Reply Last reply
    0
    • R RX Maverick

      I'm not sure that's an appropriate title but I can't think of a better one. So far I have the image resizing with the line: imageBmp = New Bitmap(imageBmp, New Size(imageWidth, imageHeight)) To me that feels sloppy, and so far I can't figure out a nice way to make a single like way to crop, and if I do I feel it will be just as bad. Am I on the wrong track? Am I just over worrying about something simple that won't save/waste processor time/power? Would it be better for me to do both at once (resize and crop) by making a second image and using DrawImage like in the code below (currently it just crops)? imageNew As Bitmap = new Bitmap(Width, Height) imageNewGraphic As Graphics = Graphics.FromImage(imageNew) imageNewGraphic.DrawImage(imgBmp, new Rectangle(0, 0, Width, Height), X, Y, Width, Height, GraphicsUnit.Pixel) I think I explained this well, I know there are other codes out there I could copy and I know that I'm reinventing the wheel, but I find I learn better this way. I'm very know to VB.NET but have had other programing training. Also this will be output to the web via ASP.NET using imageBmp.Save(Response.OutputStream, I don't believe that matters but I wanted to mention it anyway. Thanks for any help provided.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      RX Maverick wrote:

      imageBmp = New Bitmap(imageBmp, New Size(imageWidth, imageHeight)) To me that feels sloppy

      No, that's what you have to do.

      RX Maverick wrote:

      and so far I can't figure out a nice way to make a single like way to crop,

      I think you're asking if there is a "single LINE" way to crop an image. No, there isn't. You have to create a new bitmap the size you want the cropped image to be, then copy the bits from the old bitmap to the new one.

      RX Maverick wrote:

      Would it be better for me to do both at once (resize and crop) by making a second image and using DrawImage like in the code below (currently it just crops)?

      You could do it in one operation, but I wouldn't for right now. Get your app to work the way you want first, without worrying about wasting a ton of resources. If you're not constantly resizing and cropping an image, then this code should work just fine. It's one image operation. You're not really taxing the processor at all doing this.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      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