PDA

View Full Version : سوال: نوشتن متن روی عکس و ذخیره با کیفیت بالا



m_h_2007
یک شنبه 06 شهریور 1401, 00:15 صبح
با سلام خدمت اساتید. من میخوام برنامه ای مشابه متن نگار اندروید طراحی کنم. بطوریکه یک فایل تصویری لود بشه و متن دلخواه روی تصویر بنویسم و با بالاترین کیفیت تصویر نهایی رو ذخیره کنم. لطفا راهنمایی بفرمایید از چه ابزار و کلاسی استفاده کنم؟؟

mmbguide
دوشنبه 07 شهریور 1401, 09:59 صبح
سلام

لطفا لینک زیر را مشاهده کنید:
https://barnamenevis.org/showthread.php?571220-%D8%AE%D8%B7%D8%A7%DB%8C-GDI-%D9%87%D9%86%DA%AF%D8%A7%D9%85-%D8%B0%D8%AE%DB%8C%D8%B1%D9%87-%D9%81%D8%A7%DB%8C%D9%84

باید از کلاس Drawing استفاده کنید.

ShayanFiroozi
دوشنبه 07 شهریور 1401, 16:00 عصر
سلام ،
این تابع رو من در .NET Core 5 استفاده میکنم ، شاید برای بقیه فریم ورکها کمی تغییرات بخواد ، ولی کلیات رو براتون مشخص کرده !



public static void DrawPelakOnImage(Image targetImage,
string textToDraw,
Point textlocation,
Font textFont,
Color textColor,
bool drawBackground,
Color backgroundColor)
{




try
{




if (targetImage is null)
{
return;
}


if (textlocation == Point.Empty)
{
return;
}


if (textFont is null)
{
return;
}



using Graphics graphics = Graphics.FromImage(targetImage);


graphics.PageUnit = GraphicsUnit.Pixel;






// The Backgrounds must be draw first to prevent overlaping.
if (drawBackground)
{
Rectangle rect = new((textlocation.X - 160), (textlocation.Y - 3), 405, 40);


graphics.DrawRectangle(new Pen(backgroundColor), rect);
graphics.FillRectangle(new SolidBrush(backgroundColor), rect);
}




graphics.DrawString(textToDraw, textFont,new SolidBrush(textColor),textlocation);


}
catch
{
throw;
}


}