|
The file saved by this sub contains only a black rectange of the correct size. I have also tried bmp and jpg with same results.
I am using Vista 64 bit operating system and Visual Studio 2010, Traget CPU: x64, Traget FRamework: .NET Framework 4.
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
'writes to bitmap and hence the file saved
gr.DrawString(txt, the_Font, Brushes.Black, 0, 0)
' writes to screen only
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.gif)
End Using
Bitmap.Dispose()
End Sub
modified on Sunday, December 5, 2010 7:03 PM
|
|
|
|
|
...and what does this mean? A hex dump of an image files tells us nothing.
What do you mean "does not save image"?? What DOES happen? What is expected to happen? Are there any expections? What are those messages? What exactly are you trying to save? Do you have an alpha channel? What format are you trying to save in? and, the MOST important thing, WHAT IS THE CODE YOUR USING TO SAVE THE FILE?
|
|
|
|
|
I HAVE UPDATED MY POST TO INCLUDED MY CODE.
|
|
|
|
|
Ok, but NO NEED TO SHOUT about it!
|
|
|
|
|
Sorry...didn't notice cap lock on.
|
|
|
|
|
Hi,
I see you are new here, so welcome to CodeProject.
When you encounter a problem, you can ask here, and expect a number of people to try and help you; however you have to help them help you by asking a clear question, giving some context, explaining what it is you are trying and what exactly is going on and not to your liking. In this case you should explain how you are saving the image ("using program so-and-so", or "with the following code"), how you are trying to open that image again ("using program so-and-so", or "with the following code"), and then describe what exactly makes you decide it does not work. Is there an exception thrown? show it to us. etc.
With the little you provided we can not determine whether the problem, if any, is in saving the image, or in reading the image. You can't expect someone to type your hex stuff into an app to check whether it is a legal image file...
BTW: if you show a code snippet, make sure to use PRE tags, such as provided by the "code block" widget (and not CODE tags!)
|
|
|
|
|
I HAVE POST MY CODE TO THIS POST.
|
|
|
|
|
OK,
1. the initial state of a new Bitmap is all black, which corresponds to pixels with R=G=B=0, so no surprise you won't see the text from DrawString at all. Start fill a FillRectangle of the required color, probably Brushes.White
2. Not sure why the ellipse would not show. Maybe you looked over it.
3. Transparency is tricky, I hardly ever use it. Some image formats can't handle it and will ignore it, others will deal with it OK. I suggest you perform your initial experiments without transparency.
4. You have some more objects that need disposing: a Font, a Graphics.
|
|
|
|
|
Thank you for your assistance. I made the change you suggested and got a white rectangle but no text. Any suggestions?
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim rect As New System.Drawing.Rectangle
rect.Width = tWidth
rect.Height = tHeights
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
gr.FillRectangle(Brushes.White, rect)
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.Gif)
End Using
Bitmap.Dispose()
End Sub
|
|
|
|
|
just noticed, you (obviously) did round the MeasureString size from float to int, so now the text no longer fits and will get shortened/reduced to only show what fits. Try adding a few pixels to tHeights and tWidth.
BTW: you're still missing some Dispose() calls and PRE tags!
|
|
|
|
|
I'm trying to make a button that will search through a database and return a list of names of all the records matching a regular expression, plus data from a table if it exists. My first version looks like this:
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
Me.MainTableAdapter.Connection.Open()
Dim myCommand As OleDbCommand = Me.MainTableAdapter.Connection.CreateCommand()
Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
myCommand.Connection = Me.MainTableAdapter.Connection
myCommand.Transaction = Me.MainTableAdapter.Transaction
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
While dbReader.Read()
Dim title As String = dbReader("Title")
Dim ID As Integer = dbReader("ID")
Dim qualifier As String = getQualifier(ID, Me.QualifiersTableAdapter)
If Not qualifier Is Nothing Then
title &= "- " & qualifier &
End If
namesList.Items.Add(title)
End While
Me.MainTableAdapter.Connection.Close()
End Sub
Private Function getQualifier(ByVal TitleID As Integer, ByVal adapter As QualifiersTableAdapter) As String
adapter.Connection.Open()
Dim myCommand As OleDbCommand = adapter.Connection.CreateCommand()
adapter.Transaction = adapter.Connection.BeginTransaction
myCommand.Connection = adapter.Connection
myCommand.Transaction = adapter.Transaction
myCommand.CommandText = "Select * from Qualifiers WHERE Title = " & TitleID
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
myCommand.Transaction.Commit()
Dim s as String = Nothing
If dbReader.Read() Then
s = dbReader("Qualifier")
End If
adapter.Connection.Close()
Return s
End Function
This works, but it's slow if the regular expression has lots of matches. So I revised it, moving the opening and closing of the table adapter to the button click function, so that they only get performed once each time you click the search button, instead of once for every record in the DB.
(modified since original post, problem still occurs)
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
Dim dBaseConnectionString As String = "Provider=Microsoft.jet.oledb.4.0;" & _
"Data Source=demo.mdb" & ";"
Dim dBaseConnection As New OleDbConnection(dBaseConnectionString)
dBaseConnection.Open()
Dim dBaseCommand As New OleDbCommand("Select * from main WHERE Title Like '%" & titleTB.Text & "%' order by title asc, ID asc", dBaseConnection)
Dim dBaseDataReader As OleDb.OleDbDataReader = dBaseCommand.ExecuteReader()
While dBaseDataReader.Read()
Dim title As String = dbReader("Title")
Dim ID As Integer = dbReader("ID")
Dim qualifier As String = getQualifier(ID, dBaseConnection)
If Not qualifier Is Nothing Then
title &= "- " & qualifier &
End If
namesList.Items.Add(title)
End While
Me.MainTableAdapter.Connection.Close()
End Sub
Private Function getQualifier(ByVal TitleID As Integer, ByVal dBaseConnection As OleDbConnection) As String
Dim dBaseCommand As New OleDbCommand("Select * from Qualifiers WHERE Title = " & TitleID, dBaseConnection)
Dim dBaseDataReader As OleDb.OleDbDataReader = dBaseCommand.ExecuteReader()
If dbReader.Read() Then
Return dbReader("Qualifier")
Else
Return Nothing
End If
End Function
This is much faster. But I just realized something - if I use the search button enough times, I get an unhandled exception at myCommand.ExecuteReader , "Cannot open any more tables." It works fine once, even if I leave the regex blank and return everything in the database. With the old approach, I can hit the search button as many times as I want without seeing this exception.
So, what am I doing wrong here? I will admit I'm not totally comfortable with oledb and am only dimly aware of what my code is actually doing, so if you have any miscellaneous tips on how to use it better, I will listen.
Thanks.
modified on Sunday, December 5, 2010 2:50 PM
|
|
|
|
|
i_kant_spel wrote: Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
I can't find any termination of that transaction inside SearchButton_Click; try adding a Commit.
BTW: I'm a bit puzzled by the double Connection.Open/Close; and by your transactions, do you need them at all?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Sunday, December 5, 2010 5:49 AM
|
|
|
|
|
Added
myCommand.Transaction.Commit() below the button click function's Dim dbReader As OleDbDataReader = myCommand.ExecuteReader . It didn't make a difference.
Luc Pattyn wrote:
I can't find any termination of that transaction inside SearchButton_Click; try adding a Commit.
There's a good chance I've got oledb completely wrong, but I'm trying to read from two tables, so I thought I needed two table adapters, and both of them have connection properties.
It did occur to me that both adapters could share the same connection, so I changed the first function to this:
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
Dim myCommand As OleDbCommand = Me.MainTableAdapter.Connection.CreateCommand()
Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
myCommand.Connection = Me.MainTableAdapter.Connection
myCommand.Transaction = Me.MainTableAdapter.Transaction
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
myCommand.Transaction.Commit()
'stuff
Me.MainTableAdapter.Connection.Close()
End Sub
Same issue, though.
|
|
|
|
|
I'm no database expert, however I have several remarks for you:
1. I don't know why you are using transactions; the code shown only reads some data.
2. You could google "cannot open any more tables" and see a number of hits. I suggest you read a dozen of them and see if any of them ring a bell.
3. a number of database experts recommend against DataAdapters and in favor of DataReaders; you seem to mix both.
4. I would keep the code as simple as possible; only add something when you really have to.
5. You may want to provide more context when asking a question here. For instance, what has succeeded so far, how many tables/connections/transactions went well before things go wrong.
|
|
|
|
|
1 & 3 & 4:
Ok, I rewrote a big amount of the code. There are no transactions, no adapters, no strongly-typed datasets. See the original post for the new code. It still has the same problem.
2:
Yeah, I did this before posting here. I couldn't find anything that seemed to apply to my situation.
5:
If I leave titleTB.Text blank and click the search button, it will find everything in the database. This always works the first time. If I click it a second time, sometimes it works, sometimes it doesn't. IIRC, it always fails by the fifth time.
I've added some counters to the dataReader function lines, and ran it until it crashed, and looked at the counters.
The first executeReader occurs 3 times.
The first Read occurs 1320 times.
The second executeReader occurs 1319 times.
The second Read occurs 120 times.
|
|
|
|
|
i_kant_spel wrote: The first Read occurs 1320 times.
The second executeReader occurs 1319 times.
OK, you need some Dispose() calls.
While the garbage collector will eventually collect whatever objects you no longer need, it is wise to call Dispose() on those objects that are no longer in use and are instances of a class that offers a public Dispose(). This helps the system to cope with unmanaged resources, and to behave better when using scarce resources. It would not apply to objects you did not create yourself or didn't order creation of (such as PaintEventArgs.Graphics in a Paint handler).
It does apply to OleDbCommand and OleDbDataReader.
|
|
|
|
|
OleDbDataReader doesn't have a Dispose, but it does have a Close. I tried adding that to the end of the getQualifier function. Seems to have worked.
Thanks!
|
|
|
|
|
You're welcome.
|
|
|
|
|
Hi
Iam using sql server 2008. While saving time Iam getting trouble to show the size for varchar(max) field...
From the below Item_Description is Varchar(Max)
Therefore, how to pass the parameter size?......
My commands..
=============
Dim Ins_Save As String = "insert into Stock_Master (item_code,item_name,item_description) values (@item_code,@item_name,@item_description)"
MyDataAdapter.InsertCommand = New SqlCommand(Ins_Save, con)
With MyDataAdapter.InsertCommand.Parameters
.Add("@item_code", SqlDbType.VarChar, 15, "item_code")
.Add("@item_name", SqlDbType.VarChar, 30, "item_name")
.Add("@item_description", SqlDbType.VarChar, ?????????????????????, "item_description")
End With
Thanks For The Ideas
Regards
PARAMU
|
|
|
|
|
searching for SqlParameter varchar(max) I found some pages that suggest -1 would be good; I didn't find an official statement on the matter though.
|
|
|
|
|
We have a VB6 ActiveX exe program that is compiled to exe in a source library then signed and copied to the program files folder.
The program registers when we issue c:\Program Files (x86)\folder\Program.exe /REGSERVER
It is invoked by another program (QuickBooks) from the ProgramID not guidgen.
When QuickBooks invokes the program is running from the source libary (as per app.path) where it was originally compiled and signed not program files where it is registered to.
The registry has many references to the program and to the program and source library.
Can you tell me?
1. Why so many references in the registry to the source library for the activeX.exe?
2. How to get it invoked from the program files folder not the source folder.
BTW: When this is installed and setup on another machine without the source libraries it works fine.
Thanks and happy holidays!!!
|
|
|
|
|
Hi,
Can you guys check to see what I am doing wrong:
Two tables
Table_A( ID type INT, Dept_Code type INT, Name type STRING)
Table_B( ID type INT, Dept_Code, Commune_Code type nvarchar)
A view Of tableA_B (ID, dept_code, Commune_code, dept_name, commune_name)
Query:
Select * from table_A_B
where dept_code=@search or commune_code=@search
when I enter value such as 2, 3, 5; no problem
but when I do value such as 2.5,5.1.
Error: conversion failed when converting nvarchar as value to type integer.
thanks in advance
|
|
|
|
|
Yeah, this has nothing to do with VB or VB.NET. This is all SQL stuff that should be in the Database forum.
But, the error is exactly correct. In Table A, you've got Dept_Code typed as an Integer and in Table B, you don't specify a type.
You cannot supply @search to both an Integer type and an NVarChar type the same way. You also have to recognise that your cannot convert a floating point number to an Integer without data loss, so you're really NOT searching for 2.5, you're searching for 2, IF there is a hit on the Dept_Code Integer type.
|
|
|
|
|
Hi,
thanks..
Dept_code in table_B is as type INT.
When I search for 5, it is ok, but when I do 5.1 the error occurs.
Thanks again..
|
|
|
|
|
Of course it errors! 5 can be directly converted to an Integer without any data loss. 5.1 cannot.
|
|
|
|
|