-2

Using .net Framework 4.8 I have a method to resize images to thumbnails. It seems to work OK as I can see the file properties after it’s resized and all looks good. However, when I execute the save method which should save the new thumbnail to a new folder, no files are found in the new folder. All paths are correct. And I can confirm that the source files have not been altered (as expected). Lastly I’m getting no errors. Any ideas what is going wrong? This image’s original width is 600 and looking at the screenshot you can see the new width is 212, so this confirms we have a valid bitmap to save.

enter image description here

Thanks.

spacedog
  • 446
  • 3
  • 13
  • You can convert the image into Bitmapimage and Save the file in desired location – Rifat Murtuza Jul 17 '21 at 02:03
  • 2
    If you call the `Save()` method and there are no errors, **then there's a file that got written _somewhere_**. Almost certainly you've got some simple typo-like error, but without a proper [mcve] we can't even point it out. You should debug it. Note that you should really use `Path.Combine()` to combine file path elements. The way you're doing it now, whether you wind up with the path you expected will depend on whether `targetFolder` ends in a directory separator character or not. – Peter Duniho Jul 17 '21 at 02:05
  • 1
    You should inspect and post the content of `targetFolder`. Set a local variable to the value of `targetFolder + shortFileName`, see what that is then pass it to the `Save()` method. Use `Path.Combine()` to build a path (e.g., `Path.Combine(targetFolder, shortFileName));`. – Jimi Jul 17 '21 at 02:43
  • Try this, I think already answered [link](https://stackoverflow.com/questions/1258634/how-to-resize-an-image-in-c-sharp-to-a-certain-hard-disk-size) – Amit Verma Jul 17 '21 at 02:53
  • What is the _exact_ value of `targetFolder`? **Do not guess**. – mjwills Jul 17 '21 at 04:02

1 Answers1

-1

Like I have a bitmap like bmp Then Now I want to save it Like this way ....

        BitmapImage bitmapimage;

        using (MemoryStream memory = new MemoryStream())
        {
            bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
            memory.Position = 0;
            bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();
            bitmapimage.StreamSource = memory;
            bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapimage.EndInit();
            


        }
        imgQR1.Source = bitmapimage;
        string filePath = @"C:\Demo_Project\Image\test.png";
        BitmapEncoder encoder = new PngBitmapEncoder();
        encoder.Frames.Add(BitmapFrame.Create(bitmapimage));

        using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
        {
            encoder.Save(fileStream);
        }
Rifat Murtuza
  • 1,151
  • 2
  • 7
  • 15