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)
|
private static Rectangle _GetRealBounds(Bitmap bmp)
|
||||||
{
|
{
|
||||||
int minX = 0, maxX = bmp.Width - 1, minY = 0;
|
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;
|
int values = bmpData.Width * bmp.Height;
|
||||||
var rgbValues = new Int32[values];
|
var rgbValues = new Int32[values];
|
||||||
Marshal.Copy(bmpData.Scan0, rgbValues, 0, values);
|
Marshal.Copy(bmpData.Scan0, rgbValues, 0, values);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using System.Drawing.Imaging;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Draw;
|
using VocaluxeLib.Draw;
|
||||||
#if WIN
|
#if WIN
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
@@ -142,7 +143,7 @@ namespace Vocaluxe.Lib.Database
|
|||||||
g.DrawImage(origin, new Rectangle(0, 0, w, h));
|
g.DrawImage(origin, new Rectangle(0, 0, w, h));
|
||||||
|
|
||||||
data = new byte[w * h * 4];
|
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);
|
Marshal.Copy(bmpData.Scan0, data, 0, w * h * 4);
|
||||||
bmp.UnlockBits(bmpData);
|
bmp.UnlockBits(bmpData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
TextureRef = new WeakReference(textureRef);
|
TextureRef = new WeakReference(textureRef);
|
||||||
Action = action;
|
Action = action;
|
||||||
DataSize = new Size(bmp.Width, bmp.Height);
|
DataSize = bmp.GetSize();
|
||||||
Data = null;
|
Data = null;
|
||||||
DataBmp = bmp;
|
DataBmp = bmp;
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
if (bmp.Height == 0 || bmp.Width == 0)
|
if (bmp.Height == 0 || bmp.Width == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Size origSize = new Size(bmp.Width, bmp.Height);
|
Size origSize = bmp.GetSize();
|
||||||
|
|
||||||
TTextureType texture = null;
|
TTextureType texture = null;
|
||||||
_WriteBitmapToTexture(ref texture, bmp);
|
_WriteBitmapToTexture(ref texture, bmp);
|
||||||
@@ -502,7 +502,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
lock (_Textures)
|
lock (_Textures)
|
||||||
{
|
{
|
||||||
CTextureRef textureRef = _GetTextureReference(bmp.Width, bmp.Height, null);
|
CTextureRef textureRef = _GetTextureReference(bmp.GetSize(), null);
|
||||||
_TexturesToLoad.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, bmp));
|
_TexturesToLoad.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, bmp));
|
||||||
return textureRef;
|
return textureRef;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
|
|
||||||
if (_Run)
|
if (_Run)
|
||||||
{
|
{
|
||||||
|
ClearScreen();
|
||||||
_Run = _Run && CGraphics.Draw();
|
_Run = _Run && CGraphics.Draw();
|
||||||
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
|
_Run = CGraphics.UpdateGameLogic(_Keys, _Mouse);
|
||||||
_FlipBuffer();
|
_FlipBuffer();
|
||||||
@@ -281,7 +282,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
var bmp = new Bitmap(_Backbuffer);
|
var bmp = new Bitmap(_Backbuffer);
|
||||||
_Bitmaps.Add(bmp);
|
_Bitmaps.Add(bmp);
|
||||||
CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height);
|
CTextureRef texture = _GetNewTexture(bmp.GetSize());
|
||||||
|
|
||||||
// Add to Texture List
|
// Add to Texture List
|
||||||
_Textures[texture.ID] = texture;
|
_Textures[texture.ID] = texture;
|
||||||
@@ -320,7 +321,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
var bmp2 = new Bitmap(bmp);
|
var bmp2 = new Bitmap(bmp);
|
||||||
_Bitmaps.Add(bmp2);
|
_Bitmaps.Add(bmp2);
|
||||||
CTextureRef texture = _GetNewTexture(bmp.Width, bmp.Height);
|
CTextureRef texture = _GetNewTexture(bmp.GetSize());
|
||||||
|
|
||||||
// Add to Texture List
|
// Add to Texture List
|
||||||
_Textures[texture.ID] = texture;
|
_Textures[texture.ID] = texture;
|
||||||
@@ -328,9 +329,9 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
return texture;
|
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)
|
public CTextureRef AddTexture(string texturePath)
|
||||||
@@ -393,7 +394,7 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
{
|
{
|
||||||
using (var bmp = new Bitmap(w, h))
|
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);
|
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
|
||||||
bmp.UnlockBits(bmpData);
|
bmp.UnlockBits(bmpData);
|
||||||
return AddTexture(bmp);
|
return AddTexture(bmp);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -134,5 +135,15 @@ namespace VocaluxeLib
|
|||||||
rect.H + 2 * rect.H * (scale - 1f),
|
rect.H + 2 * rect.H * (scale - 1f),
|
||||||
rect.Z);
|
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