Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C#-Version
- public unsafe System.Drawing.Image Bitmap() {
- System.Drawing.Bitmap result = new System.Drawing.Bitmap( ( int )dimensions.width, ( int )dimensions.height );
- System.Drawing.Imaging.BitmapData Information
- = result.LockBits( new System.Drawing.Rectangle( 0, 0, ( int )dimensions.width, ( int )dimensions.height ), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
- int x, y, pos;
- for ( y = 0; y < ( int )dimensions.height; y++ ) {
- for ( x = 0; x < ( int )dimensions.width; x++ ) {
- pos = Information.Scan0.ToInt32() + x * 4 + y * Information.Width * 4;
- *( byte* )( pos + 3 ) = pixels[x, y].a;
- *( byte* )( pos + 2 ) = pixels[x, y].r;
- *( byte* )( pos + 1 ) = pixels[x, y].g;
- *( byte* )pos = pixels[x, y].b;
- }
- }
- result.UnlockBits( Information );
- return result;
- }
- C++-Version
- GX_INLINE Gdiplus::Bitmap *Image::Bitmap( void ) const {
- Gdiplus::Bitmap* result = new Gdiplus::Bitmap( ( int )width, ( int )height, PixelFormat32bppPARGB );
- Gdiplus::BitmapData info;
- int x, y, stride;
- byte *ptr, *scan0;
- OpenGX::Pixel currentPixel;
- stride = info.Stride;
- scan0 = ( byte* )info.Scan0;
- result->LockBits( &Gdiplus::Rect( 0, 0, ( int )width, ( int )height ), Gdiplus::ImageLockMode::ImageLockModeRead | Gdiplus::ImageLockMode::ImageLockModeWrite, PixelFormat32bppPARGB, &info );
- for( y = 0; y < ( int )height; y++ ) {
- for( x = 0; x < ( int )width; x++ ) {
- ptr = scan0 + x * 4 + y * stride;
- currentPixel = pixels[x][y];
- *( ptr + 3 ) = currentPixel.a;
- *( ptr + 2 ) = currentPixel.r;
- *( ptr + 1 ) = currentPixel.g;
- *( ptr ) = currentPixel.b;
- }
- }
- result->UnlockBits( &info );
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment