Add extension methods for bitmap GetSize and GetRect
This commit is contained in:
1 parent
016b7627d1
commit
d1e9fbaff1
5 files changed
+23
-10
No files matched your search
@@ -161,7 +161,7 @@ namespace Vocaluxe.Base.Fonts
|
||||
private static Rectangle _GetRealBounds(Bitmap bmp)
|
||||
{
|
||||
int minX = 0, maxX = bmp.Width - 1, minY = 0;
|
||||
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
int values = bmpData.Width * bmp.Height;
|
||||
var rgbValues = new Int32[values];
|
||||
Marshal.Copy(bmpData.Scan0, rgbValues, 0, values);
|
||||
|
||||
@@ -22,6 +22,7 @@ using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vocaluxe.Base;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
#if WIN
|
||||
using System.Data.SQLite;
|
||||
@@ -142,7 +143,7 @@ namespace Vocaluxe.Lib.Database
|
||||
g.DrawImage(origin, new Rectangle(0, 0, w, h));
|
||||
|
||||
data = new byte[w * h * 4];
|
||||
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
Marshal.Copy(bmpData.Scan0, data, 0, w * h * 4);
|
||||
bmp.UnlockBits(bmpData);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
TextureRef = new WeakReference(textureRef);
|
||||
Action = action;
|
||||
DataSize = new Size(bmp.Width, bmp.Height);
|
||||
DataSize = bmp.GetSize();
|
||||
Data = null;
|
||||
DataBmp = bmp;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
if (bmp.Height == 0 || bmp.Width == 0)
|
||||
return null;
|
||||
|
||||
Size origSize = new Size(bmp.Width, bmp.Height);
|
||||
Size origSize = bmp.GetSize();
|
||||
|
||||
TTextureType texture = null;
|
||||
_WriteBitmapToTexture(ref texture, bmp);
|
||||
@@ -502,7 +502,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
lock (_Textures)
|
||||
{
|
||||
CTextureRef textureRef = _GetTextureReference(bmp.Width, bmp.Height, null);
|
||||
CTextureRef textureRef = _GetTextureReference(bmp.GetSize(), null);
|
||||
_TexturesToLoad.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, bmp));
|
||||
return textureRef;
|
||||
}
|
||||
|
||||
@@ -232,6 +232,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
|
||||
if (_Run)
|
||||
{
|
||||
ClearScreen();
|
||||
_Run = _Run && CGraphics.Draw();
|
||||
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
|
||||
_FlipBuffer();
|
||||
@@ -281,7 +282,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
var bmp = new Bitmap(_Backbuffer);
|
||||
_Bitmaps.Add(bmp);
|
||||
CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height);
|
||||
CTextureRef texture = _GetNewTexture(bmp.GetSize());
|
||||
|
||||
// Add to Texture List
|
||||
_Textures[texture.ID] = texture;
|
||||
@@ -320,7 +321,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
var bmp2 = new Bitmap(bmp);
|
||||
_Bitmaps.Add(bmp2);
|
||||
CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height);
|
||||
CTextureRef texture = _GetNewTexture(bmp.GetSize());
|
||||
|
||||
// Add to Texture List
|
||||
_Textures[texture.ID] = texture;
|
||||
@@ -328,9 +329,9 @@ namespace Vocaluxe.Lib.Draw
|
||||
return texture;
|
||||
}
|
||||
|
||||
private CTextureRef _GetNewTexture(int w, int h)
|
||||
private CTextureRef _GetNewTexture(Size size)
|
||||
{
|
||||
return new CTextureRef(_Bitmaps.Count - 1, new Size(w, h));
|
||||
return new CTextureRef(_Bitmaps.Count - 1, size);
|
||||
}
|
||||
|
||||
public CTextureRef AddTexture(string texturePath)
|
||||
@@ -393,7 +394,7 @@ namespace Vocaluxe.Lib.Draw
|
||||
{
|
||||
using (var bmp = new Bitmap(w, h))
|
||||
{
|
||||
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
BitmapData bmpData = bmp.LockBits(bmp.GetRect(), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
|
||||
bmp.UnlockBits(bmpData);
|
||||
return AddTexture(bmp);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
@@ -134,5 +135,15 @@ namespace VocaluxeLib
|
||||
rect.H + 2 * rect.H * (scale - 1f),
|
||||
rect.Z);
|
||||
}
|
||||
|
||||
public static Size GetSize(this Bitmap bmp)
|
||||
{
|
||||
return new Size(bmp.Width, bmp.Height);
|
||||
}
|
||||
|
||||
public static Rectangle GetRect(this Bitmap bmp)
|
||||
{
|
||||
return new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user