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. C#
  4. Zooming Using Matrices....

Zooming Using Matrices....

Scheduled Pinned Locked Moved C#
graphicscsharpwinformsquestion
4 Posts 3 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.
  • N Offline
    N Offline
    NortonC
    wrote on last edited by
    #1

    Hi, I'm quite new to C# especially when using GDI+. I saw the solution for zooming an image, but I didn't manage to zoom. I couldn't quite understand what the parameters in "new Matrix(scale,0,0,scale, xoffest, yoffset);" mean I think In order to zoom my image by 25% I implemented your code in the following way: float scale = 25f/100f; pictureBox.Image.Save("OriginalImage.png",ImageFormat.Png); Graphics g = Graphics.FromImage(pictureBox.Image); g.Transform = new Matrix(scale,0,0,scale, 0, 0); pictureBox.Image.Save("ResizedImage.png", ImageFormat.Png); pictureBox.Image = Image.FromFile("ResizedImage.png"); //to load the new image What am I doing wrong please? Thanks A Lot! C.N.

    J 1 Reply Last reply
    0
    • N NortonC

      Hi, I'm quite new to C# especially when using GDI+. I saw the solution for zooming an image, but I didn't manage to zoom. I couldn't quite understand what the parameters in "new Matrix(scale,0,0,scale, xoffest, yoffset);" mean I think In order to zoom my image by 25% I implemented your code in the following way: float scale = 25f/100f; pictureBox.Image.Save("OriginalImage.png",ImageFormat.Png); Graphics g = Graphics.FromImage(pictureBox.Image); g.Transform = new Matrix(scale,0,0,scale, 0, 0); pictureBox.Image.Save("ResizedImage.png", ImageFormat.Png); pictureBox.Image = Image.FromFile("ResizedImage.png"); //to load the new image What am I doing wrong please? Thanks A Lot! C.N.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      You are scaling the System.Drawing.Graphics object. But that has no effect on the actual System.Drawing.Image object in the PictureBox.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice Judah Himango

      N 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        You are scaling the System.Drawing.Graphics object. But that has no effect on the actual System.Drawing.Image object in the PictureBox.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice Judah Himango

        N Offline
        N Offline
        NortonC
        wrote on last edited by
        #3

        Hi, can you kindly give me an example of how can I zoom an image in a PictureBox using the Matrix method (as I had shown in the code-snippet) or any other method please? Thanks C.N.

        J 1 Reply Last reply
        0
        • N NortonC

          Hi, can you kindly give me an example of how can I zoom an image in a PictureBox using the Matrix method (as I had shown in the code-snippet) or any other method please? Thanks C.N.

          J Offline
          J Offline
          John Arlen1
          wrote on last edited by
          #4

          You are not zooming the image itself. Instead, you are telling the view (Graphics) how to render the image. This is the advantage of using Transforms... drawing code does not change. Just the parameters of the rendering. Derive a class from PictureBox (or control type of choice...) and modify the OnPaint routine appropriately. public class ZoomPictureBox : PictureBox { private float m_zoom = 1.0F; public float Zoom { get{ return m_zoom; } set{ m_zoom = value; if( this.Image != null ) Invalidate(); } protected override void OnPaint(PaintEventArgs e) { Matrix matrix = new Matrix(); matrix.Scale( m_zoom, m_zoom ); e.Graphics.Transform = matrix; e.Graphics.DrawImageUnscaled( this.Image, 0, 0 ); // base.OnPaint (e); } }

          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