Image image(L"F:\\MyPictures\\1.jpg"); TextureBrush tBrush(&image);
Pen texturedPen(&tBrush, 10); graphics.DrawLine(&texturedPen, 25, 25, 325, 25);
tBrush.SetWrapMode(WrapModeTileFlipXY);
graphics.FillRectangle(&tBrush, 25, 100, 300, 200);
如题,运行第一句就出现内存不可读的错误
代码是从网上复制的,其中F:\\MyPictures\\1.jpg为我自己的图片的路径,确实存在
请教高人啊

解决方案 »

  1.   

    没有初始化GDI+,在程序初始化时调用GdiplusStartup,例如:
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
      

  2.   

    已经初始化了
    我已经画出了一些东西,比如用PathGradientBrush画一个颜色渐变的Pie
    但是用到上面代码的时候就出错了...
    不知道原因
      

  3.   

    另外,我在SDI/MDI中可以画图,但在基于对话框的程序中使用GDI+怎么没有效果?
    CPaintDC dc(this);
    Graphics graphics(dc.m_hDC);
    Pen pen(Color(255,0,0,255));
    graphics.DrawLine(&pen,Point(10,10),Point(250,220));
    执行以上代码没有任何反应!
    PS:GDI+的相应配置都做好了
      

  4.   

    第一句就报错了
    Image image(L"F:\\MyPictures\\1.jpg"); 
      

  5.   

    后一个问题解决了,是因为我下面红色的2句代码一开始加错位置了,加到对话框显示之后了
             GdiplusStartupInput gdiplusInput;
    GdiplusStartup(&m_gdiplusToken,&gdiplusInput,NULL);
    CGDIPlusDlgDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    }
    GdiplusShutdown(m_gdiplusToken);
    同样的,在MDI程序中,我把那2句代码放到ShowWindow之前就好了,不再报错!
    可为什么在MDI程序中,那2句代码放在ShowWindow之后可以画其它图形,单单无法显示Image?