Skia~setdibitstodevice~windows

Source: Internet
Author: User
Tags drawtext skia

Problem: Skia is a graphics library, itself does not have the ability to draw on the device, can be provided by the Skview class, reference to achieve on different platform equipment painting.

The SkOsWindow_Win.cpp:onPaint method provides an interface that is plotted on a Windows platform device, SetDIBitsToDevice ();

1 SetDIBitsToDevice (2HDC HDC,//The device environment handle. 3                 intXdest,//specifies the x-coordinate of the upper-left corner of the destination rectangle, which represents coordinates in logical units. 4                 intYdest,//indicates the y-coordinate of the upper-left corner of the target rectangle, in logical units. 5DWORD Dwwidth,//Specifies the width of the DIB, expressed in logical units. 6DWORD Dwheight,//Specifies the height of the DIB, expressed in logical units. 7                 intXSRC,//specifies the x-coordinate of the lower-left corner of the Dib bitmap, representing the coordinates in logical units8                 intYSRC,//Specifies the y-coordinate of the lower-left corner of the Dib bitmap, represented by logical units. 9UINT Ustartscan,//Specifies the starting scan line in the DIB. TenUINT Cscanlines,//Specifies the number of Dib scan lines contained in the array to which the parameter lpvbits points.  OneCONST VOID *lpvbits,//A pointer to an array of byte types that store the DIB color data.  ACONST Bitmapinfo *lpbmi,//A pointer to the BITMAPINFO structure that contains information about the DIB.  -UINT Fucoloruse//points to the member bmicolors in the BITMAPINFO structure whether it contains an explicit RGB value or a value that indexes the color palette.  -)
SetDIBitsToDevice
1 voidSkoswindow::d Opaint (void*CTX) {2      This-Update (NULL);3 4     if(Knone_backendtype = =fattached)5     {6HDC HDC =(HDC) ctx;7         Constskbitmap& bitmap = This-Getbitmap ();8 9 bitmapinfo BMI;Tenmemset (&BMI,0,sizeof(BMI)); OneBmi.bmiHeader.biSize =sizeof(bitmapinfoheader); ABmi.bmiHeader.biWidth =bitmap.width (); -Bmi.bmiHeader.biHeight =-bitmap.height ();//Top-down Image -Bmi.bmiHeader.biPlanes =1; theBmi.bmiHeader.biBitCount = +; -Bmi.bmiHeader.biCompression =Bi_rgb; -Bmi.bmiHeader.biSizeImage =0; -  +         // -         //Do the setdibitstodevice. +         // A         //TODO (Wjmaclean): at         //Fix This call to handle skbitmaps that has rowbytes! = width, -         //i.e. may has padding at the end of lines. The Skassert below -         //May is ignored by builds, and the only obviously safe option -         //Seems to is to copy the bitmap to a temporary (contiguous) -         //buffer before passing to SetDIBitsToDevice (). -Skassert (Bitmap.width () * bitmap.bytesperpixel () = =bitmap.rowbytes ()); in bitmap.lockpixels (); -         intRET =SetDIBitsToDevice (HDC, to             0,0, + bitmap.width (), Bitmap.height (), -             0,0, the             0, Bitmap.height (), * bitmap.getpixels (), $&BMI,Panax Notoginseng dib_rgb_colors); -(void) ret;//we ' re ignoring potential failures for now. the bitmap.unlockpixels (); +     } A}
Skoswindow_win.cpp

1 //establishing a logical coordinate system2Paint.setargb (255,255,0,0);3Paint.setstrokewidth (3);4Canvas->drawline (0,0, Bitmap->width (),0, paint);5Canvas->drawline (0,0,0, bitmap->height (), paint);6 7Paint.setargb (255,255, $, $);8Canvas->drawtext ("X/2",4, Bitmap->width ()/2+Ten,Ten, paint);9Canvas->drawtext ("Y/2",4,5, Bitmap->height ()/2, paint);Ten  OnePaint.setargb (255,255, $,0); ACanvas->drawtext ("X",2, Bitmap->width ()-Ten,Ten, paint); -Canvas->drawtext ("Y",2,5, Bitmap->height (), paint);
establishing a coordinate system
1 //Three conceptual window areas, canvas area, bitmap bitmap area2 SetDIBitsToDevice (HDC,3                 0,0,//Specifies the coordinate origin of the logical coordinate system (that is, the canvas Canavs), the upper-left corner (i.e., right, bottom, positive direction),4Bitmap->width (), bitmap->height (),5                 0,0,6                 0,//start display position in canvas7Bitmap->height (), Bitmap->getpixels (),//The starting point of the scan and the height of the scan8&LPBMI, dib_rgb_colors);
three regions

By setting a brush to fill a complete drawing area, the canvas's drawing area is always a bitmap area, and

In the bitmap transformation, the logical coordinates of the canvas (the upper-left corner of the screen, right and bottom), while the bitmap's logical coordinates are the lower left (right, top), all transformations in the bitmap display transform have an inverted operation.

That is:.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.