Re: Сохранение битмапа - кто короче ?
От: ole! США http://files.rsdn.org/4543/rsdn.gif
Дата: 28.11.01 11:30
Оценка: 17 (3)
Здравствуйте Hollander, Вы писали:


H>Привет !


H>Встретил топик похожий, налабал решение попроще. Так можно сохранять хучь битмапы, хучь иконки, хучь метафайлы и вообще все объекты, поддерживающие IPicture. Написал на Cи — так круче.


даешь GDI+ в массы!!!



/// пример не в тему, зато позволяет сохранять в bmp,jpeg,gif,emf,tiff,png
/// содран с PlatformSDK/GDI+/Setting JPEG Compression Level

#include <Stdio.h>
#include <Objbase.h>
#include <Windows.h>
#include <Gdiplus.h>
using namespace Gdiplus;

// Helper functions
int GetCodecClsid(const WCHAR*, CLSID*);

int main()
{
   CLSID              codecClsid;
   EncoderParameters  encoderParameters;
   long               quality;
   Status             stat;

   // Get an image from the disk.
   Image image(L"Shapes.bmp");

   // Get the CLSID of the JPEG codec.
   GetCodecClsid(L"image/jpeg", &codecClsid);

   // Before we call Image::Save, we must initialize an
   // EncoderParameters object. The EncoderParameters object
   // has an array of EncoderParameter objects. In this
   // case, there is only one EncoderParameter object in the array.
   // The one EncoderParameter object has an array of values.
   // In this case, there is only one value (of type LONG)
   // in the array. We will set this value to 0, 50, and 100.

   encoderParameters.Count = 1;
   encoderParameters.Parameter[0].Guid = EncoderQuality;
   encoderParameters.Parameter[0].Type = ValueTypeLong;
   encoderParameters.Parameter[0].NumberOfValues = 1;

   // Save the image as a JPEG with quality level 0.
   quality = 0;
   encoderParameters.Parameter[0].Value = &quality;
   stat = image.Save(L"Shapes001.jpg", &codecClsid, &encoderParameters);

   if(stat == Ok)
      wprintf(L"%s saved successfully.\n", L"Shapes001.jpg");
   else
      wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes001.jpg");

   // Save the image as a JPEG with quality level 50.
   quality = 50;
   encoderParameters.Parameter[0].Value = &quality;
   stat = image.Save(L"Shapes050.jpg", &codecClsid, &encoderParameters);

   if(stat == Ok)
      wprintf(L"%s saved successfully.\n", L"Shapes050.jpg");
   else
      wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes050.jpg");

   // Save the image as a JPEG with quality level 100.
   quality = 100;
   encoderParameters.Parameter[0].Value = &quality;
   stat = image.Save(L"Shapes100.jpg", &codecClsid, &encoderParameters);

   if(stat == Ok)
      wprintf(L"%s saved successfully.\n", L"Shapes100.jpg");
   else
      wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes100.jpg");

   return 0;
} // main




/// snipped
my $.02
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.