Daniel Lip
Daniel Lip

Reputation: 11317

Is there any way to save a bitmap in a lower resolution then Jpeg ? To change the resolution manual?

I have this code:

int ISampleGrabberCB.BufferCB(double sampleTime, IntPtr pBuffer, int bufferLen)
        {

            if (Form1.ExtractAutomatic == true)
            {
                using (var bitmap = new Bitmap(_width, _height, _width * 3, PixelFormat.Format24bppRgb, pBuffer))
                {
                    if (!this.Secondpass)
                    {
                        long[] HistogramValues = Form1.GetHistogram(bitmap);
                        Form1.Histograms.Add(HistogramValues);
                        long t = Form1.GetTopLumAmount(HistogramValues, 1000);
                        Form1.averagesTest.Add(t);

                    }
                    else
                    {

                        if (_frameId > 0)
                        {
                            double t = Form1.averagesTest[_frameId] / 1000.0 - Form1.averagesTest[_frameId - 1] / 1000.0;
                            w.WriteLine("averagesTest >>>  " + t);
                            if (_frameId == 1049)
                            {
                                w.Close();
                            }
                            if (Form1.averagesTest[_frameId] / 1000.0 - Form1.averagesTest[_frameId - 1] / 1000.0 > 60.0)                                {
                                count = 6;
                            }

                            if (count > 0)
                            {
                                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
                                bitmap.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".jpg"),ImageFormat.Jpeg);
                                count --;
                            }

Before that i SAved the bitmap as Bitmap .bmp now i changed it to Jpeg .jpg but is there anyway to change the jpg to be saved in a lower resolution ? Maybe manual change somehow ?

bitmap.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".jpg"),ImageFormat.Jpeg);

Instead saving it as just jpeg maybe to save it as jpeg but with a much lower resolution. The reason is that i want to show each Bitmap Histogram and also to show in the same time the image/frame it self in the pictureBox but i if i will be able to save it in lower resolution the saving process will be faster.

Since i want to check the histograms i dont mind if the images/frames will be show in a low resolution in this case.

Upvotes: 0

Views: 1205

Answers (1)

Hans Passant
Hans Passant

Reputation: 941545

Resolution has no effect at all on the saved image file. It is a reference number, it indicated how large the image was (in inches) on the device that created the image.

It gets to be important when you display an image on a device that has a radically different resolution. A good example would be an image that you created in a paint program on your machine. And then print on paper.

In your paint program you'd create, say, an image of 1600 x 900 pixels and it filled the entire screen of your laptop, all 14 inches of it. If you then print it on a printer with a 600 dots-per-inch resolution then that same image would be 1600/600 x 900/600 = 2.7 x 1.5 inches. It turned into a postage stamp on paper.

To avoid that, the image has be rescaled so it also takes 14 inches on paper. The resolution reference number in the image permits this rescaling. Your paint program recorded the resolution of your monitor, say 120 dots per inch. When you print it and see the printer has a 600 dots per inch resolution, you know you'll need to print the image 5 times as big to get it the same size on paper.

To get the image to save faster you need to make it smaller. In pixels. The Bitmap(Image, Size) constructor is a simple way to do that.

Upvotes: 3

Related Questions