Pictures DPI code changes

1. Use C # modify the image DPI

private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
this.textBox1.Text = ((string[])e.Data.GetData(DataFormats.FileDrop.ToString()))[0];
}

}

private void textBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

using (Bitmap newImage = new Bitmap(Image.FromFile(this.textBox1.Text)))
                {
                    newImage.SetResolution(300, 300);
                    newImage.Save("123.jpg",
                        System.Drawing.Imaging.ImageFormat.Jpeg);
                }

The above is a winform window drag and drop files, then modify the image DPI. The test is successful, you can modify normal.

2. VC modify the image DPI

Consistent with the principles of the code and C #, but can not be modified successfully.

Use GDIPlus

GetImageCLSID int (const WCHAR * format, the CLSID pClsid *)
{
// get the value encoded in the format of an image file format, GUID value to access the image format stored in a COM component in pClsid
UINT NUM = 0;
UINT size = 0;

ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);

IF (size == 0)
return FALSE; // encoded information is not available

// allocate memory
pImageCodecInfo = (ImageCodecInfo *) (the malloc (size));
IF (pImageCodecInfo == NULL)
return FALSE; // allocation failure

// get coding system available all information
GetImageEncoders (num, size, pImageCodecInfo) ;

// Find available encoded information format if the format is supported
for (UINT I = 0; I <NUM; I ++)
{
// the MimeType: specifically described coding scheme
if (wcscmp (pImageCodecInfo [i] .MimeType, format ) == 0)
{
* pClsid = pImageCodecInfo [I] .Clsid;
Free (pImageCodecInfo);
return TRUE;
}
}

free(pImageCodecInfo);
return FALSE;
}

 

Gdiplus::Bitmap bitPic(m_wcFile,FALSE);
bitPic.SetResolution(300,300);
CLSID clImageClsid;
GetImageCLSID(L"image/jpeg", &clImageClsid);
bitPic.Save(L"123.jpg",&clImageClsid);

The principle is the same, why not, of unknown origin, record

Guess you like

Origin www.cnblogs.com/nightnine/p/11728121.html