Create an Image

P

Programmer

Hi all
Here is my problem

I want to create an image so i can pass it on an object to put it as
watermark in my pdf report

Here is what i have write so far

Dim objBitmap As System.Drawing.Bitmap

Dim objGraphics As System.Drawing.Graphics

Dim cstream As System.IO.MemoryStream

Dim c As System.Drawing.Image



objBitmap = New System.Drawing.Bitmap(width, height)

objGraphics = System.Drawing.Graphics.FromImage(objBitmap)

Dim drawFont As New System.Drawing.Font("Arial", 32)

Dim drawBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Black)

' Create point for upper-left corner of drawing.

Dim x As Single = 0.0F

Dim y As Single = 0.0F

' Set format of string.

Dim drawFormat As New System.Drawing.StringFormat

drawFormat.FormatFlags = System.Drawing.StringFormatFlags.DirectionVertical

g.DrawString("IMAGE TEXT", drawFont, drawBrush, x, y, drawFormat)

objBitmap.save ("c:\temp\a.jpg")

objBitmap.Save(cstream, System.Drawing.Imaging.ImageFormat.Jpeg)

c = System.Drawing.Image.FromStream(cstream)

c.Save("c:\temp\b.jpg")



Now if you look at the a.jpg and b.jpg the a.jpg contains an image that
writes the "IMAGE TEXT"

but b.jpg is totaly BLACK!!!!!



What i'm doing wrong??

Thank you for your time
 
K

Ken Tucker [MVP]

Hi,

Think you are draw the string off the visible area of the bitmap.
This should work.
Dim bm As New Bitmap(50, 50)

Dim g As Graphics = Graphics.FromImage(bm)

g.Clear(Color.Black)

g.TranslateTransform(25, 25)

g.RotateTransform(90)

g.DrawString("Hi", Me.Font, Brushes.White, 0, 0)



Ken

--------------------------

Hi all
Here is my problem

I want to create an image so i can pass it on an object to put it as
watermark in my pdf report

Here is what i have write so far

Dim objBitmap As System.Drawing.Bitmap

Dim objGraphics As System.Drawing.Graphics

Dim cstream As System.IO.MemoryStream

Dim c As System.Drawing.Image



objBitmap = New System.Drawing.Bitmap(width, height)

objGraphics = System.Drawing.Graphics.FromImage(objBitmap)

Dim drawFont As New System.Drawing.Font("Arial", 32)

Dim drawBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Black)

' Create point for upper-left corner of drawing.

Dim x As Single = 0.0F

Dim y As Single = 0.0F

' Set format of string.

Dim drawFormat As New System.Drawing.StringFormat

drawFormat.FormatFlags = System.Drawing.StringFormatFlags.DirectionVertical

g.DrawString("IMAGE TEXT", drawFont, drawBrush, x, y, drawFormat)

objBitmap.save ("c:\temp\a.jpg")

objBitmap.Save(cstream, System.Drawing.Imaging.ImageFormat.Jpeg)

c = System.Drawing.Image.FromStream(cstream)

c.Save("c:\temp\b.jpg")



Now if you look at the a.jpg and b.jpg the a.jpg contains an image that
writes the "IMAGE TEXT"

but b.jpg is totaly BLACK!!!!!



What i'm doing wrong??

Thank you for your time
 
P

Programmer

No that's not it
If you run the code the image is draw in a visible area.
That's the reason Save both files phisicaly to see if it's ok
The Bitmap is created succesfully and it also saved succesfully.

But then i try to pass it on an image object the image.save is black.

If i save the bitmap in a file (let's say "c:\temp\bitmap.jpg")
and instead of calling Image.FromStream(cstream) i call
Image.FromFile(c:\temp\bitmap.jpg")
the image is loaded succesfully!!!!!! and the save method of the image
Object
creates exactly the same image. With the text in it!!!!!!!

Please notice that i want the image object to pass it on an other function

Thank you for your time
Please help me
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top