471,313 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,313 software developers and data experts.

Create an Image

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.Bla ck)

' 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


Jul 21 '05 #1
2 2964
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

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

"Programmer" <se*******@hotmail.com> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
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.Bla ck)

' 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



Jul 21 '05 #2
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Oq**************@TK2MSFTNGP14.phx.gbl...
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

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

"Programmer" <se*******@hotmail.com> wrote in message
news:um**************@TK2MSFTNGP15.phx.gbl...
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.Bla ck)

' 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


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steve Amey | last post: by
6 posts views Thread by David W. Simmonds | last post: by
2 posts views Thread by Mango | last post: by
2 posts views Thread by Programmer | last post: by
4 posts views Thread by John Daly | last post: by
3 posts views Thread by pedrito | last post: by
11 posts views Thread by =?Utf-8?B?UGV0ZXIgSw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.