По поводу перевода из C# в VB...
Релиб
Форумы       Участники    Календарь    Кто он-лайн?
Добро пожаловать, гость ( Вход | Регистрация )
        



По поводу перевода из C# в VB... Expand / Collapse
Автор
Сообщение
27.03.2006 23:05
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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 кода)
Сообщ. #893793
28.03.2006 3:45


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

участник
Last Login: 29.10.2007 19:07
Сообщ.: 292, Visits: 3 426
Здесь (см. ссылку) вставь свой код выбери из какого куда переводить, нажми кнопку "GO", подожди чуток и будет тебе счастье :)
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
Сообщ. #893800
28.03.2006 20:16
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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;
}
}
}


та штука, что таится под ссылкой лажу полную показывает
Сообщ. #893932
« пред. тема | след. тема »


Эту тему читают Expand / Collapse
Посетители: 0 (0 гостей, 0 участников, 0 скрыт.участников)
Сейчас нет участников, просматривающих тему.
Модераторы: Alexey, boombastik, bazile, pl, Alexey Spirin

Время GMT +3:00, Сейчас 8:22