Форум: Форум C++Разное
Новые темы: 00
PHP Puzzles. Авторы: Кузнецов М.В., Симдянов И.В. Социальная инженерия и социальные хакеры. Авторы: Кузнецов М.В., Симдянов И.В. PHP 5. На примерах. Авторы: Кузнецов М.В., Симдянов И.В., Голышев С.В. PHP на примерах (2 издание). Авторы: Кузнецов М.В., Симдянов И.В. MySQL на примерах. Авторы: Кузнецов М.В., Симдянов И.В.
ВСЕ НАШИ КНИГИ
Консультационный центр SoftTime

Форум C++

Выбрать другой форум

 

Здравствуйте, Посетитель!

вид форума:
Линейный форум Структурный форум

тема: нужна помощь по С++!!!!!!!!!!!!!!!
 
 автор: gragory   (18.02.2010 в 10:54)   письмо автору
 
 

подскажите,
как сделать рамку вокруг картинки,хранящейся в битмапе?
или как добавлять в битмап фрагмент другого?

используя mfc и gdi+ на студии

  Ответить  
 
 автор: heed   (19.02.2010 в 20:07)
 
   для: gragory   (18.02.2010 в 10:54)
 

в msdn что-то вроде такого примера по обрезке, вставке и ресайза
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;

VOID OnPaint(HDC hdc)
{
   Graphics graphics(hdc);
Image image(L"1.jpg");
UINT width = image.GetWidth();
UINT height = image.GetHeight();

// Make the destination rectangle 30 percent wider and
// 30 percent taller than the original image.# не знаю как будет в 3 рааза меньше
// Put the upper-left corner of the destination
// rectangle at (20, 20).
Rect destinationRect(20, 20, (int)(0.5 * width), (int)(0.5 * height));


// Draw the image unaltered with its upper-left corner at (10, 10).
graphics.DrawImage(&image, 10, 10);

// Draw a portion of the image. Scale that portion of the image
// so that it fills the destination rectangle
graphics.DrawImage(
   &image,
   destinationRect,
   0, 0,              // upper-left corner of source rectangle
   0.75 * width,      // width of source rectangle
   0.75 * height,     // height of source rectangle
   UnitPixel);
}

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
   HWND                hWnd;
   MSG                 msg;
   WNDCLASS            wndClass;
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR           gdiplusToken;
   
   // Initialize GDI+.
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
   wndClass.style          = CS_HREDRAW | CS_VREDRAW;
   wndClass.lpfnWndProc    = WndProc;
   wndClass.cbClsExtra     = 0;
   wndClass.cbWndExtra     = 0;
   wndClass.hInstance      = hInstance;
   wndClass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
   wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wndClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wndClass.lpszMenuName   = NULL;
   wndClass.lpszClassName  = TEXT("GettingStarted");
   
   RegisterClass(&wndClass);
   
   hWnd = CreateWindow(
      TEXT("GettingStarted"),   // window class name
      TEXT("Getting Started"),  // window caption
      WS_OVERLAPPEDWINDOW,      // window style
      CW_USEDEFAULT,            // initial x position
      CW_USEDEFAULT,            // initial y position
      CW_USEDEFAULT,            // initial x size
      CW_USEDEFAULT,            // initial y size
      NULL,                     // parent window handle
      NULL,                     // window menu handle
      hInstance,                // program instance handle
      NULL);                    // creation parameters
  
   ShowWindow(hWnd, iCmdShow);
   UpdateWindow(hWnd);
   
   while(GetMessage(&msg, NULL, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
   
   GdiplusShutdown(gdiplusToken);
   return (int) msg.wParam;
}  // WinMain

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, 
   WPARAM wParam, LPARAM lParam)
{
   HDC          hdc;
   PAINTSTRUCT  ps;  
   switch(message)
   {
   case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      OnPaint(hdc);
      EndPaint(hWnd, &ps);
      return 0;
   case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
   }
} // WndProc

если ещё убрал пару warnings приведя к (int)
Rect destinationRect(20, 20, (int)(0.5 * width), (int)(0.5 * height));
, то что-то насчёт двух таких-же
warning C4244: 'argument' : conversion from 'double' to 'INT', possible loss of data

не понял вообще что должно быть в последнем параметре
graphics.DrawImage(
&image,
destinationRect,
0, 0,
0.75 * width, 0.75 * height,
UnitPixel);

запускал подсоввя 128х128 1.jpg
было-бы интересно поразбираться,) но не интересно

  Ответить  
Rambler's Top100
вверх

Rambler's Top100 Яндекс.Метрика Яндекс цитирования