473,749 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

overlay text on uploaded picture

My web site accepts uploaded photos and stores them in a SQL table as BLObs
so they never touch the filesystem.

I have a way to create a thumbnail version of the uploaded image and store
that in the db too, again without touching metal.

I need a way to overlay some text on the image but I'm stuck.

All the help I find uses files in the filesystem, and when I try to convert
the example to my imagestream model it fails and I can't figure out why. I'm
not big on graphics, so I need some help.

Here's the (working) code I use to get the uploaded image down to a
thumbnail size...
Private Function createThumbnail (ByVal ImageStream As Stream, ByVal tWidth
As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing. Image
Dim thumbSize As Size
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Try
g = System.Drawing. Image.FromStrea m(ImageStream)
thumbSize = NewthumbSize(g. Width, g.Height, tWidth, tHeight)
imgOutput = New Bitmap(g, thumbSize.Width , thumbSize.Heigh t)
imgStream = New MemoryStream
thisFormat = g.RawFormat
imgOutput.Save( imgStream, thisFormat)
ReDim imgbin(imgStrea m.Length)
imgStream.Posit ion = 0
n = imgStream.Read( imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
g.Dispose()
imgOutput.Dispo se()
End Try
Return imgbin
End Function

And here's the (non-working) code I need fixing to get text onto the
original image.

Private Function createProof(ByV al ImageStream As Stream) As Byte()
Dim image As System.Drawing. Image
Dim graphic As System.Drawing. Graphics
Dim imgOutput As Bitmap
Dim imgStream As MemoryStream
Dim thisFormat As Object
Dim imgbin() As Byte
Dim n As Int32
Dim myBrush As Drawing2D.Hatch Brush
Dim myFont As Font
Try
image = System.Drawing. Image.FromStrea m(ImageStream)
myBrush = New Drawing2D.Hatch Brush(Drawing2D .HatchStyle.Tre llis,
Color.FromArgb( 127, Color.White))
myFont = New Font("Arial black", 144)
graphic = Graphics.FromIm age(image)
graphic.DrawStr ing("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))
imgOutput = New Bitmap(image.Wi dth, image.Height, graphic)
imgStream = New MemoryStream
imgOutput.Save( imgStream, image.RawFormat )
ReDim imgbin(imgStrea m.Length)
imgStream.Posit ion = 0
n = imgStream.Read( imgbin, 0, imgbin.Length)
Catch ex As Exception
Throw ex
Finally
graphic.Dispose ()
imgOutput.Dispo se()
End Try
Return imgbin
End Function

Help me out someone, please...

Brian Lowe
---------@
Nov 18 '05 #1
5 4872
In article <u7************ **@tk2msftngp13 .phx.gbl>, no@reply.address
says...
My web site accepts uploaded photos and stores them in a SQL table as BLObs
so they never touch the filesystem.

I have a way to create a thumbnail version of the uploaded image and store
that in the db too, again without touching metal.

I need a way to overlay some text on the image but I'm stuck.


Just a guess, but I would try using the Graphics.FromIm age() method to
get a Graphics object and then you should be able to do your overlay
with that.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #2
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Just a guess, but I would try using the Graphics.FromIm age() method to
get a Graphics object and then you should be able to do your overlay
with that.


Thanks. I figured I needed a Graphics object, and also that I'd need the
FromImage() method to get my image into a form I could lay text on.

Here's my code so far...

' I have my image data as a System.IO.Strea m but
' I need a System.Drawing. Graphics object
' Graphics won't convert a stream but System.Drawing. Image
' will and Graphics will convert an Image so...
image = System.Drawing. Image.FromStrea m(ImageStream)
graphic = Graphics.FromIm age(image)
' Now I have my image data as a Graphics object
' Set up tools for writing text...
myBrush = New Drawing2D.Hatch Brush(Drawing2D .HatchStyle.Tre llis,
Color.FromArgb( 127, Color.White))
myFont = New Font("Arial black", 144)
' Use the DrawString() method of the graphics object to
' overlay the text (tell me if I'm wrong, please)
graphic.DrawStr ing("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))
' I can convert a Stream to a byte array and that's what
' I need to output. I can convert a Bitmap into a Stream, so...
' Create a Bitmap of the correct width and
' hieght using my Grpahics object image
imgOutput = New Bitmap(image.Wi dth, image.Height, graphic)
' Prepare a new Stream
imgStream = New MemoryStream
' Send the Bitmap down the Stream
imgOutput.Save( imgStream, image.RawFormat )
' Prepare the Byte array to take the stream data
ReDim imgbin(imgStrea m.Length)
' Set the pointer to the start of the stream
imgStream.Posit ion = 0
' Stream the Bitmap data into the Byte array
n = imgStream.Read( imgbin, 0, imgbin.Length)

That's the plan, anyway.

I end up with an image the right size but all black.

I don't see how I can even debug this stuff - there's nothing I can look at
between steps to show me where my graphic is up to.

I'm stuck.

Brian Lowe
---------@


Nov 18 '05 #3
In article <eS************ *@TK2MSFTNGP12. phx.gbl>, no@reply.address
says...
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Just a guess, but I would try using the Graphics.FromIm age() method to
get a Graphics object and then you should be able to do your overlay
with that.


Thanks. I figured I needed a Graphics object, and also that I'd need the
FromImage() method to get my image into a form I could lay text on.

Here's my code so far...

' I have my image data as a System.IO.Strea m but
' I need a System.Drawing. Graphics object
' Graphics won't convert a stream but System.Drawing. Image
' will and Graphics will convert an Image so...
image = System.Drawing. Image.FromStrea m(ImageStream)
graphic = Graphics.FromIm age(image)
' Now I have my image data as a Graphics object
' Set up tools for writing text...
myBrush = New Drawing2D.Hatch Brush(Drawing2D .HatchStyle.Tre llis,
Color.FromArgb( 127, Color.White))
myFont = New Font("Arial black", 144)
' Use the DrawString() method of the graphics object to
' overlay the text (tell me if I'm wrong, please)
graphic.DrawStr ing("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))


At this point, the bitmap pointed to by "image" should have the text on
it and you can directly save the "image" object. No need to create a
second bitmap.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 18 '05 #4

"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
In article <eS************ *@TK2MSFTNGP12. phx.gbl>, no@reply.address
' Use the DrawString() method of the graphics object to
' overlay the text (tell me if I'm wrong, please)
graphic.DrawStr ing("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))

At this point, the bitmap pointed to by "image" should have the text on
it and you can directly save the "image" object. No need to create a
second bitmap.


Really? I thought .net always used ByVal by default and not ByRef. That
would mean that the image is being modfied as a side effect of methods on a
graphic object created from it. Is that right?

If it is then all I need to do is stream my original (but changed) image
back to a Byte array and I'll be able to store it in SQl as before.

I'll be very happy.

I'll let you know how I get on. Thanks for the help.
The reason I was creating a second bitmap is that I need the image in the
form of a Byte array (so I can then load it into a SQL binary field).

I couldn't go direct from a Graphics object to a Byte array (can I?) so I
loaded the graphic into a Bitmap and then saved it to a Stream and converted
the Stream into a Byte array.

I know its a kludge, and I'm sure there's a very neat and streamlined way to
do what I want, but my limited knowledge of the tools means I need help.

' I can convert a Stream to a byte array and that's what
' I need to output. I can convert a Bitmap into a Stream, so...
' Create a Bitmap of the correct width and
' height using my Graphics object image
imgOutput = New Bitmap(image.Wi dth, image.Height, graphic)
' Prepare a new Stream
imgStream = New MemoryStream
' Send the Bitmap down the Stream
imgOutput.Save( imgStream, image.RawFormat )
' Prepare the Byte array to take the stream data
ReDim imgbin(imgStrea m.Length)
' Set the pointer to the start of the stream
imgStream.Posit ion = 0
' Stream the Bitmap data into the Byte array
n = imgStream.Read( imgbin, 0, imgbin.Length)

Brian Lowe
---------@
Nov 18 '05 #5
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
In article <eS************ *@TK2MSFTNGP12. phx.gbl>, no@reply.address
says...
"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com... image = System.Drawing. Image.FromStrea m(ImageStream)
graphic = Graphics.FromIm age(image)
' Now I have my image data as a Graphics object
' Set up tools for writing text...
myBrush = New Drawing2D.Hatch Brush(Drawing2D .HatchStyle.Tre llis,
Color.FromArgb( 127, Color.White))
myFont = New Font("Arial black", 144)
' Use the DrawString() method of the graphics object to
' overlay the text (tell me if I'm wrong, please)
graphic.DrawStr ing("PROOF", myFont, myBrush, New RectangleF(10, 10, 100,
200))


At this point, the bitmap pointed to by "image" should have the text on
it and you can directly save the "image" object. No need to create a
second bitmap.


I understood the default to be ByVal when passing parameters into functions,
so I'd expect graphic to be a copy of image, so anything I do to it would
not change image. Am I wrong?

Obviously I am/was.

I tried saving image and lo! there was my text overlaid on the picture.

Thanks!

Next job is to work out how to size my text so it adequately covers enough
of the picture to be worth stamping "PROOF" on it. Not too small as to
appear only in a corner, and not too large as to darw outside of the image
area.

Thanks for your help.

Brian Lowe
---------@
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5594
by: Gilad Barkan | last post by:
Dear Colleagues, My task: I read AVI file and get handle to its frames using the Ray Mercer's outstanding tutorial regarding video in VB. Now, I try to write text on each such frame and then save them to an AVI file. Since each frame retrieved from AVI file, as I understand it, is a bitmap, then my task is reduced to writing text on bitmaps (I know how to save AVI from collection of bitmaps). Does anyone have such a code / link how to...
4
5778
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
5
2788
by: Fabri | last post by:
Someone call please tell me why this simple code: ================================================================= <html> <head> <title>Example</title> <style type="text/css"> #msg{ position: absolute; background-color: white;
9
5005
by: Ross | last post by:
it seems that it is only supported by w3c but not IE or netscape, but what is a w3c browser ?
0
5676
by: Never Best | last post by:
I'm having troubles attaching the Device to a window using its hWnd, and I have some troubles with getting transparancy to work with a DDOverlay... if anyone could help it would be greatlay appreasated. Here is some of my code. The Transparancy isn't working because the ColorSpaceLow/HighValue isn't set... The Line" overFX.DestinationColorKey.ColorSpaceLowValue = Color.White" returns the error "Cannot Modify the return value because it...
1
3927
by: sendhil | last post by:
hi, Iam doing some graphics programming with C#. I have to create a Windows MetaFile from a base64 encoded string. How do i create the file. I want to Overlay this Windows MetaFile on a image which is present in a Picture box. Any ideas to do this? Thanks senthil
3
7633
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover 100% of the image, and all I would need is a set of horizontal and vertical lines over the image to create a grid overlay. Two requirements would be to:
5
3872
by: pravinnweb | last post by:
i have dropdown select menu in my page. when i click here link the black overlay comes .in FF overlay working fine but in IE6 the select option menu appeared on overlay...please help me thanks in advance! here is the code <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>LIGHTBOX EXAMPLE</title>
1
3954
by: linksterman | last post by:
I want to make a simple app to overlay subtitles on youtube videos. Is there a way to do this and keep the files hosted on youtubes servers (eg just overlay the text with another flash app)? I have researched simple FLV players as a way to overlay text, but so far it seems youtube is being very hard at making the direct URL to the FLV very hard to obtain.
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.