|
|
|
Forum Guru
      
участник
Last Login: 06.01.2008 10:33
Сообщ.: 70,
Visits: 678
|
|
Подскажите, пожалуйста, реально ли переписать процедурину под VB.NET2005?
public static void ColouriseWatermark(
Bitmap watermark,
Color backColor
)
{
// Get the reference colour:
Color refColor = watermark.GetPixel(0, 0);
float refLuminance = refColor.GetBrightness();
float backHue = backColor.GetHue();
float backSaturation = backColor.GetSaturation();
// Loop through all the pixels, adjusting the hue,
// saturation and luminance according to the desired
// background colour:
// Lock the bitmap bits
BitmapData bmData = watermark.LockBits(
new Rectangle(0, 0, watermark.Width, watermark.Height),
ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
IntPtr scan0 = bmData.Scan0;
unsafe
{
byte * pDest = (byte *)(void *)scan0;
for (int y = 0; y < watermark.Height; ++y)
{
for (int x = 0; x < watermark.Width; ++x)
{
// Get HLS of existing colour:
Color pixel = Color.FromArgb(pDest[2], pDest[1], pDest[0]);
float lumOffset = pixel.GetBrightness() / refLuminance;
// Apply the offset to the reference luminance:
float lumPixel = backColor.GetBrightness() * lumOffset;
// Calculate the new colour
HLSRGB newPixel = new HLSRGB(backHue, lumPixel, backSaturation);
// set the values:
pDest[0] = newPixel.Blue;
pDest[1] = newPixel.Green;
pDest[2] = newPixel.Red;
// leave alpha alone
// Move to next BGRA
pDest += 4;
}
}
}
watermark.UnlockBits(bmData);
}
Если нельзя напрямую, то может подскажет какой нибудь аналог этой процедуры? (без использования unsafe кода)
|
|
|
|
|
Supreme Being
      
участник
Last Login: 29.10.2007 19:07
Сообщ.: 292,
Visits: 3 426
|
|
Здесь (см. ссылку) вставь свой код выбери из какого куда переводить, нажми кнопку "GO", подожди чуток и будет тебе счастье :)
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
|
|
|
|
|
Forum Guru
      
участник
Last Login: 06.01.2008 10:33
Сообщ.: 70,
Visits: 678
|
|
Меня конкретно интересует перевод вот этого куска:
unsafe
{
byte * pDest = (byte *)(void *)scan0;
for (int y = 0; y < watermark.Height; ++y)
{
for (int x = 0; x < watermark.Width; ++x)
{
// Get HLS of existing colour:
Color pixel = Color.FromArgb(pDest[2], pDest[1], pDest[0]);
float lumOffset = pixel.GetBrightness() / refLuminance;
// Apply the offset to the reference luminance:
float lumPixel = backColor.GetBrightness() * lumOffset;
// Calculate the new colour
HLSRGB newPixel = new HLSRGB(backHue, lumPixel, backSaturation);
// set the values:
pDest[0] = newPixel.Blue;
pDest[1] = newPixel.Green;
pDest[2] = newPixel.Red;
// leave alpha alone
// Move to next BGRA
pDest += 4;
}
}
}
та штука, что таится под ссылкой лажу полную показывает
|
|
|
|