BugInTheSYS

Untitled

Dec 1st, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. C#-Version
  2. public unsafe System.Drawing.Image Bitmap() {
  3. System.Drawing.Bitmap result = new System.Drawing.Bitmap( ( int )dimensions.width, ( int )dimensions.height );
  4. System.Drawing.Imaging.BitmapData Information
  5. = result.LockBits( new System.Drawing.Rectangle( 0, 0, ( int )dimensions.width, ( int )dimensions.height ), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
  6. int x, y, pos;
  7. for ( y = 0; y < ( int )dimensions.height; y++ ) {
  8. for ( x = 0; x < ( int )dimensions.width; x++ ) {
  9. pos = Information.Scan0.ToInt32() + x * 4 + y * Information.Width * 4;
  10. *( byte* )( pos + 3 ) = pixels[x, y].a;
  11. *( byte* )( pos + 2 ) = pixels[x, y].r;
  12. *( byte* )( pos + 1 ) = pixels[x, y].g;
  13. *( byte* )pos = pixels[x, y].b;
  14. }
  15. }
  16. result.UnlockBits( Information );
  17. return result;
  18. }
  19.  
  20. C++-Version
  21. GX_INLINE Gdiplus::Bitmap *Image::Bitmap( void ) const {
  22. Gdiplus::Bitmap* result = new Gdiplus::Bitmap( ( int )width, ( int )height, PixelFormat32bppPARGB );
  23. Gdiplus::BitmapData info;
  24. int x, y, stride;
  25. byte *ptr, *scan0;
  26. OpenGX::Pixel currentPixel;
  27. stride = info.Stride;
  28. scan0 = ( byte* )info.Scan0;
  29. result->LockBits( &Gdiplus::Rect( 0, 0, ( int )width, ( int )height ), Gdiplus::ImageLockMode::ImageLockModeRead | Gdiplus::ImageLockMode::ImageLockModeWrite, PixelFormat32bppPARGB, &info );
  30. for( y = 0; y < ( int )height; y++ ) {
  31. for( x = 0; x < ( int )width; x++ ) {
  32. ptr = scan0 + x * 4 + y * stride;
  33. currentPixel = pixels[x][y];
  34. *( ptr + 3 ) = currentPixel.a;
  35. *( ptr + 2 ) = currentPixel.r;
  36. *( ptr + 1 ) = currentPixel.g;
  37. *( ptr ) = currentPixel.b;
  38. }
  39. }
  40. result->UnlockBits( &info );
  41. return result;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment