PC Review


Reply
Thread Tools Rate Thread

Create an Image

 
 
Programmer
Guest
Posts: n/a
 
      17th May 2005
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






 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      17th May 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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







 
Reply With Quote
 
Programmer
Guest
Posts: n/a
 
      18th May 2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create image thumbnail without opening complete image =?Utf-8?B?TWFyayBSLiBEYXdzb24=?= Microsoft C# .NET 2 18th Oct 2005 04:14 PM
create an iso image in c# cs Microsoft C# .NET 0 21st May 2004 05:15 PM
Read Bitmap and create Method to Create Image at runtime Mark Johnson Microsoft Dot NET Framework 1 28th Nov 2003 08:26 PM
How to create smaller image from a bigger image - please help ! Anand Ganesh Microsoft C# .NET 0 14th Jul 2003 05:14 PM
Please help. How to create a small image from a big image - Any Suggestions Please ? Anand Ganesh Microsoft C# .NET 0 14th Jul 2003 05:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:22 AM.