tags:

views:

1571

answers:

5

Hi to all,

To zoom images in and out, there is a possible way to resize the pictureBox and showing image in strechmode. Although I can not use it efficiently becauce in general over 8x it gives storage error [think that a pictureBox has the Size(32k, 32k) it needs over 1GB memory !

Is there a special method, or should I zoom only the seen part of the image by using ImageClone ?

Kind Regards, to all.

+1  A: 

I personally would just zoom the visible part as the rest is hidden anyway (and thus no use)

Scoregraphic
+1  A: 

By using the matrix object and the transform property of your graphics object:

using(Graphics g = this.CreateGraphics())
{
    using(Bitmap youPicture = new Bitmap(yourPictureFile))
    {
        g.DrawImage(youPicture, 0, 0, 300, 100); //set the desired size

        //Now you need to create a matrix object to apply transformation on your graphic
        Matrix mat = new Matrix();
        mat.Scale(1.5f, 1.5f, MatrixOrder.Append); //zoom to 150%
        g.Transform = mat;

        g.DrawImage(youPicture, new Rectangle(...), 0, 0, youPicture.Width,
            youPicture.Height, GraphicsUnit.Pixel) ;
    }
}
Francis B.
This doesn't really answer the question as it is...
codekaizen
I dont think you're right, I give him an alternative that is perflectly ok for his problem.
Francis B.
+1  A: 

See this answer to an earlier question. You definitely don't want to zoom by making the image huge and showing only part of it - you'll run into the memory problem that you've already encountered. Also, the stretch mode of a picture box doesn't use high-quality interpolation, so the result will look pretty crappy.

In the answer I linked here, I included a link to a C# project that shows you how to do this kind of zooming.

Update: here is a direct link to the downloadable project.

MusiGenesis
A: 

to Francis B.

Your code is working, but the code-user should pay attention that

g.DrawImage(youPicture, new Rectangle(...), 0, 0, youPicture.Width, youPicture.Height, GraphicsUnit.Pixel) ;

The new Rectangle(...) must have the same Size with the original Image, if not the DrawImage method would scale the image again.

What if, I want to move the zoomed image? The zoomed image would gone away part by part ... I need a movable zoomed Image.

to MusiGenesis

I've looked at the project. The idea is not much different and DrawImage method is scaling the picture to given rectengular [same as resizing]. By drawing images or something different to show it easier, but after using method the zoom images are disposed so that you can not modify them ...

Cmptrb
I apologize, but I have no idea what you're saying here.
MusiGenesis
I will put here a small project soon, I know I can not explain clearly. So after you run the project you will understand what I meant.
Cmptrb
A: 

Here is the project at first try to zoom at the project [impossible, storage error] than delete the 41. line in form.cs :

pictureBox1.Image = youPicture;

After deleting this line, the program will work, please move the zoomed image.

here is the link :

http://rapidshare.com/files/265835370/zoomMatrix.rar.html

Sorry being late :( [if the image can not be displayed, you can change it from properties.]

Cmptrb