Move a bitmap data block in memory to another bitmap

Source: Internet
Author: User

These pure learningCodeNo practical use

Bitmap can replicate data faster than setpixel.

Static void main (string [] ARGs) {// screenshot code rectangle rec = screen. primaryscreen. bounds; bitmap IMG = new Bitmap (Rec. width, Rec. height); graphics gph = graphics. fromimage (IMG); gph. copyfromscreen (new point (0, 0), new point (0, 0), REC. size); // lock bitmap to system memory. drawing. imaging. bitmapdata bmp data = IMG. lockbits (REC, system. drawing. imaging. imagelockmode. readwrite, system. drawing. imaging. pixelformat. format16bpprgb555); // obtain the address of the starting row. intptr = BMP data. scan0; // defines an array to save bitmap data. int bytes = BMP data. stride * IMG. height; byte [] rgbvalues = new byte [bytes]; // copy the RGB value to the array system. runtime. interopservices. marshal. copy (PTR, rgbvalues, 0, bytes); IMG. unlockbits (BMP data); // copy the data to another bitmap. Bitmap img2 = new Bitmap (Rec. width, Rec. height); graphics gph2 = graphics. fromimage (img2); system. drawing. imaging. bitmapdata BMP data2 = img2.lockbits (REC, system. drawing. imaging. imagelockmode. readwrite, system. drawing. imaging. pixelformat. format16bpprgb555); intptr ptr2 = BMP data2.scan0; system. runtime. interopservices. marshal. copy (rgbvalues, 0, ptr2, bytes); img2.unlockbits (BMP data2); img2.save ("asd.jpg", system. drawing. imaging. imageformat. JPEG );}

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.