1. Use C# to 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];
}
}< /p>
private void textBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
using (Bitmap newImage = new Bitmap( Image.FromFile(this.textBox1.Text)))
Imagine, 123, jpg, newImage. ImageFormat.Jpeg);
}
The above is the winform window to drag and drop the file, and then modify the image DPI. The test is successful and you can modify it normally.
2. VC modifies the picture DPI
The code principle is the same as C#, but it cannot be modified successfully.
Use GDIPlus
int GetImageCLSID(const WCHAR *format, CLSID *pCLSID)
{
//Get the encoding value of the image file in format, access the The GUID value of the COM component of the format image is stored in pCLSID
UINT num = 0;
UINT size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size) ;
if(size == 0)
return FALSE; // Coding information is not available
//Allocate memory
pImageCodecInfo = (ImageCodecInfo*)(malloc( size));
if(pImageCodecInfo == NULL)
return FALSE; // allocation failed
// get all the information about the encoding methods available in the system
GetImageEncoders(num, size, pImageCodecInfo);
//Find out whether the format format is supported in the available encoding information
for(UINT i = 0; i
//MimeType: specific description of the encoding method
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”imag e/jpeg”, &clImageClsid);
bitPic.Save(L”123.jpg”,&clImageClsid);
The principle is the same, why not work, the reason is to be investigated and recorded
p>