PDA

View Full Version : تولید یک عکس تک بیتی



milad5843
سه شنبه 19 آبان 1388, 15:05 عصر
با سلام

من با دستوراتى كه در زير ميبيند يك متن رو تبديل به عكس كردم ولى يه مشكلى كه هست اينه كه كه اين عكسِ كوچيكى كه تولیدش ميكنم وقتى zoom ميكنى روش كاملا مشكى نيست یعنیi تك بيتى نيست بلكه از يه طیف رنگ تشكيل شده ، چى كار بايد بكنم كه pixel ها فقط سفيد يا مشكى باشه ، لطفا عكس و كدِ رو ببينيد.

با تشكر.

http://www.barnamenevis.org/forum/attachment.php?attachmentid=39547&stc=1&d=1257722802




Dim Text As String = TextBox1.Text 'tayin mikonad ke ma neveshte mikhahim
Dim FontColor As Color = Color.Black 'range neveshteye ax
Dim BackColor As Color = Color.White 'range bg ax
Dim FontName As String = "tahoma" 'font ax
Dim FontSize As Integer = andaze(1) 'size fonte ax
Dim Height As Integer = 8 'arze ax be pixel
Dim Width As Integer = 32 'toole ax be pixel
Dim objBitmap As New Bitmap(Width, Height) 'moteghayerist ke sizash width o height ast
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim objColor As New Color
Dim objFont As New Font(FontName, FontSize)
Dim objPoint As New PointF(0, y(1))
Dim objBrushForeColor As New SolidBrush(FontColor)
Dim objBrushBackColor As New SolidBrush(BackColor)

objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint)
objBitmap.Save(Application.StartupPath & "\step1" & ".bmp", ImageFormat.Bmp)

milad5843
پنج شنبه 21 آبان 1388, 00:33 صبح
بابا یعنی کسی نظری نداره ؟

ghafarifar
پنج شنبه 21 آبان 1388, 17:49 عصر
این کد رو امتحان کن


Dim objBitmap As New Bitmap(500, 500) 'moteghayerist ke sizash width o height ast
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim drawString As [String] = ""
' Create font and brush.
Dim drawFont As New Font("tahoma", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create rectangle for drawing.
Dim x As Single = 150.0F
Dim y As Single = 150.0F
Dim width As Single = 200.0F
Dim height As Single = 50.0F
Dim drawRect As New RectangleF(x, y, width, height)
' Draw rectangle to screen.
Dim blackPen As New Pen(Color.Black)
' objGraphics.DrawRectangle(blackPen, x, y, width, height)
' Draw string to screen.
objGraphics.DrawString(drawString, drawFont, drawBrush, drawRect)
objBitmap.Save("c:\step1" & ".png", ImageFormat.Png)

milad5843
پنج شنبه 21 آبان 1388, 22:20 عصر
این کد رو امتحان کن


Dim objBitmap As New Bitmap(500, 500) 'moteghayerist ke sizash width o height ast
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim drawString As [String] = ""
' Create font and brush.
Dim drawFont As New Font("tahoma", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create rectangle for drawing.
Dim x As Single = 150.0F
Dim y As Single = 150.0F
Dim width As Single = 200.0F
Dim height As Single = 50.0F
Dim drawRect As New RectangleF(x, y, width, height)
' Draw rectangle to screen.
Dim blackPen As New Pen(Color.Black)
' objGraphics.DrawRectangle(blackPen, x, y, width, height)
' Draw string to screen.
objGraphics.DrawString(drawString, drawFont, drawBrush, drawRect)
objBitmap.Save("c:\step1" & ".png", ImageFormat.Png)



ممنون اما کد شما فقط یک عکس با زمینه مشکی ایجاد میکند.
من بک کالر سفید هم تعریف کردم ولی جواب نداد.
میشه اصلاحش کنید ؟

ghafarifar
جمعه 22 آبان 1388, 00:00 صبح
من مقدار string رو چیزی نداده بودم واسه همین سیاه شده بود این رو امتحان کن


Dim objBitmap As New Bitmap(500, 500) 'moteghayerist ke sizash width o height ast
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim drawString As [String] = "in yek test ast"
' Create font and brush.
Dim drawFont As New Font("tahoma", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create rectangle for drawing.
Dim x As Single = 150.0F
Dim y As Single = 150.0F
Dim width As Single = 200.0F
Dim height As Single = 50.0F
Dim drawRect As New RectangleF(x, y, width, height)
' Draw rectangle to screen.
Dim blackPen As New Pen(Color.Black)
' objGraphics.DrawRectangle(blackPen, x, y, width, height)
' Draw string to screen.
objGraphics.DrawString(drawString, drawFont, drawBrush, drawRect)
objBitmap.Save("c:\step1" & ".png", Imaging.ImageFormat.Png)

milad5843
جمعه 22 آبان 1388, 09:19 صبح
فرقی نکرد . بازم یه عکسه تمام مشکیه !

ghafarifar
جمعه 22 آبان 1388, 11:27 صبح
این کدی که برات گذاشتم با فرمت png خوب جواب میده ولی با فرمت های دیگه نه . تا زمانی که زمینه عکست Transparent باشه مشکلی نیست ولی اگه عوضش کنی میشه یه چیزی شبیه همون عکسی که خودت آپلود کردی . امیدوارم که تونسته باشم بهت کمک کنم موفق باشی



Dim objBitmap As New Bitmap(500, 500, 16, Imaging.PixelFormat.Format32bppArgb, New IntPtr) 'moteghayerist ke sizash width o height ast
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
Dim drawString As [String] = "in yek test ast"
' Create font and brush.
Dim drawFont As New Font("tahoma", 16)
Dim drawBrush As New SolidBrush(Color.Black)
' Create rectangle for drawing.
Dim x As Single = 150.0F
Dim y As Single = 150.0F
Dim width As Single = 200.0F
Dim height As Single = 50.0F
Dim drawRect As New RectangleF(x, y, width, height)
objGraphics.FillRectangle(Brushes.Transparent, drawRect)
' Draw rectangle to screen.
' Dim blackPen As New Pen(Color.Blue)
' objGraphics.DrawRectangle(blackPen, x, y, width, height)
' Draw string to screen.
objGraphics.DrawString(drawString, drawFont, drawBrush, drawRect)
objBitmap.Save("c:\step1" & ".png", Imaging.ImageFormat.Png)

milad5843
جمعه 22 آبان 1388, 23:25 عصر
مرسی
ولی حالا میدونی مشکل چیه ؟ چون عکسم ریزه قاطی پاطی نشون میده. مجبورم از همون کد قبلی استفاده کنم !!!! قسمت نبود از کد شما استفاده کنیم.