Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to compress image on linux?
    primarykey
    data
    text
    <p>I am writing function to compress image using GDI+ on windows, and it's working well,</p> <pre><code>void ImageProcessorImpl::compressImpl(const std::string&amp; path, int size, UInt8 quality) { HBITMAP hbmReturn = NULL; Bitmap* bmPhoto = NULL; std::wstring upath; UnicodeConverter::toUTF16(path, upath); // make source file close automatically, Bitmap detructor will be called { Bitmap image(upath.c_str()); int srcWidth = image.GetWidth(); int srcHeight = image.GetHeight(); float percent = 0; int destX = 0, destY = 0; if (srcWidth &gt; srcHeight) { percent = ((float)size/(float)srcWidth); destX = (int)((size - (srcWidth * percent))/2); } else { percent = ((float)size/(float)srcHeight); destY = (int)((size - (srcHeight * percent))/2); } if (percent &gt;= 1.0f) return; // skip compress int destWidth = (int)(srcWidth * percent); int destHeight = (int)(srcHeight * percent); bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat24bppRGB); bmPhoto-&gt;SetResolution(image.GetHorizontalResolution(), image.GetVerticalResolution()); Graphics *grPhoto = Graphics::FromImage(bmPhoto); Color colorW(255, 255, 255, 255); grPhoto-&gt;Clear(colorW); grPhoto-&gt;SetInterpolationMode(InterpolationModeHighQualityBicubic); grPhoto-&gt;DrawImage(&amp;image, Rect(destX, destY, destWidth, destHeight)); bmPhoto-&gt;GetHBITMAP(colorW, &amp;hbmReturn); delete grPhoto; } // end source image file, Bitmap image(upath.c_str()); // find appropriate encoder, jpeg CLSID encoderClsid; getEncoderClsid(L"image/jpeg", &amp;encoderClsid); // set output quality for jpeg alone EncoderParameters encoderParameters; setEncoderQuality(&amp;encoderParameters, &amp;quality); // output to image file with desired quality bmPhoto-&gt;Save(upath.c_str(), &amp;encoderClsid, &amp;encoderParameters); // release resources delete bmPhoto; DeleteObject(hbmReturn); } int ImageProcessorImpl::getEncoderClsid(const WCHAR* format, void* clsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&amp;num, &amp;size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for (UINT j = 0; j &lt; num; ++j) { if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) { *(CLSID*)clsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; //Success } } free(pImageCodecInfo); return -1; // Failure } void ImageProcessorImpl::setEncoderQuality(void* params, UInt8* quality) { EncoderParameters* encoderParams = (EncoderParameters*)params; encoderParams-&gt;Count = 1; encoderParams-&gt;Parameter[0].Guid = EncoderQuality; encoderParams-&gt;Parameter[0].Type = EncoderParameterValueTypeLong; encoderParams-&gt;Parameter[0].NumberOfValues = 1; encoderParams-&gt;Parameter[0].Value = quality; } </code></pre> <p>But, I want to have this function on linux, I don't know what lib I can use to implement such function on linux, who can help me? Thnx</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload