question

$$ANON_USER$$ avatar image
0 Votes"
$$ANON_USER$$ asked $$ANON_USER$$ edited

Enlarge in picture ?

I have a picture I want to enlarge it 5x. I have the codes to make the picture 5x smaller. How can I reverse these codes.
So, how can I enlarge the picture with Pixel Replacement?

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered $$ANON_USER$$ commented

If you really want to zoom the image by repeating the pixels in loops, maybe with some colour replacement, then try this code too:

 Color WriteColor, ChangeColor;
 Bitmap FirstImage, LastImage;
 FirstImage = pictureBox1.Image as Bitmap ?? new Bitmap( pictureBox1.Image );
 int ImageWidth = FirstImage.Width;
 int ImageHeight = FirstImage.Height;
 const int Coefficient = 5;
 LastImage = new Bitmap( ImageWidth * Coefficient, ImageHeight * Coefficient );
    
 for( int x1 = 0, x2 = 0; x1 < ImageWidth; ++x1, x2 += Coefficient )
 {
     for( int y1 = 0, y2 = 0; y1 < ImageHeight; ++y1, y2 += Coefficient )
     {
         WriteColor = FirstImage.GetPixel( x1, y1 );
         ChangeColor = WriteColor;
         for( int x = x2; x < x2 + Coefficient; ++x )
         {
             for( int y = y2; y < y2 + Coefficient; ++y )
             {
                 LastImage.SetPixel( x, y, ChangeColor );
             }
         }
     }
 }
 pictureBox2.Image = LastImage;
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Man you are great. The code really worked. Thank you.

0 Votes 0 ·
Viorel-1 avatar image
0 Votes"
Viorel-1 answered $$ANON_USER$$ commented

To obtain a zoomed image, having larger size:

 var new_image = new Bitmap( pictureBox1.Image, pictureBox1.Image.Width * 5, pictureBox1.Image.Height * 5 );
 pictureBox2.Image = new_image;

To zoom and keep the size of original image (crop):

 using( var scaled_image = new Bitmap( pictureBox1.Image, pictureBox1.Image.Width * 5, pictureBox1.Image.Height * 5 ) )
 {
     var new_image = new Bitmap( pictureBox1.Image.Width, pictureBox1.Image.Height );
    
     using( var g = Graphics.FromImage( new_image ) )
     {
         g.DrawImage( scaled_image, Point.Empty );
     }
    
     pictureBox2.Image = new_image;
 }



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks. Don't I need commands like in the code I'm sharing? like "for"

Ex:
for (int x1 = 0; x1 < ImageWidth; x1 = x1 + Coefficient)
{
y2 = 0;
for (int y1 = 0; y1 < ImageHeight; y1 = y1 + Coefficient)

0 Votes 0 ·

The pixels are copied by the shown constructor of Bitmap, which resizes the image. You do not have to process the pixels in your loops unless you need some different features.

0 Votes 0 ·

I understood thank you. I said it because I have to process pixels in my project.

0 Votes 0 ·

So, how can I zoom the picture with the Pixel Replacement Method?? Thanks.

0 Votes 0 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered $$ANON_USER$$ commented

...and you can see the usual doc :

How to: Crop and Scale Images


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thanks i will look...

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered karenpayneoregon commented

The following comes from the following GitHub repository but has issues.

Here is the modified version in the following GitHub repository with full source.

83854-custompicturebox.png

.NET Core version


Source

83995-custompicturebox.png



· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I could not run the file. I think it is related to the version of the framework.

0 Votes 0 ·

I added .NET Core version project to my original reply. The issue was that since there was no namespace for struct ProTransformation the compiler looked outside the project while enclosing struct ProTransformation in a namespace resolved the issue.

0 Votes 0 ·