如何在图像上写入图像并通过vb.net编码保存输出 [英] how to write image on image and save the out put via vb.net codding

查看:176
本文介绍了如何在图像上写入图像并通过vb.net编码保存输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends


我是vb.net的初学者,我有需要完成的任务,即我有两个文件夹,一个有背景图像,另一个有字母数字字符图像(所有图像均为jpeg)

现在我需要在背景图像中写入字母数字字符,并且应该将输出的图像与字母数字图像一起保存,如何在vb.net中做

1.如果我在文本框中输入文本,则vb.code应该与字符文件夹中的字符匹配并显示在背景图像中,并且需要将输出保存为background + character,

例如,如果我在文本框中输入"Test",代码喊出相关字符图像,例如"T","e","S","T",并粘贴到背景图像中,则应与背景一起保存带有字符
的图像
请有人帮我提供代码

问候
grlinks

Hi Friends


i am beginner for vb.net , i have task that needs to completed , that is i''ve two folders one is having background images another one is have alpha numeric character images(all images are jpeg)

now i need to write alpha numeric character into the background images and out put should be saved background images with alpha numeric images , how do i do in vb.net

1. if i enter the text into the text box , vb.code should match the character from character folder and displayed into the background image and need save that output with background + character ,

for example if i type "Test" in to text box , code shout get the related character images like "T","e","S","T" , paste to the background images, and it should be saved with background images with character

please some one help me for code

regards
grlinks

推荐答案

由于这听起来很像作业,因此无需编写代码-您应该自己做点什么!

将工作分解为逻辑部分:
1)将背景图片放入应用程序中.
2)将文本从文本框中转换为单独的图像.
3)将每个图像添加到背景
4)保存修改后的图像.

这些都不是难事:
1)简单:查看 Image.FromFile [ TextBox.Text [^ ]属性
2b)将文本分成单独的字符:请参见 String.ToCharArray [
Since this sounds a lot like homework, no code - you should do something yourself!

Break the job into logical parts:
1) Get your background image into your application.
2) Convert text from textbox into separate images.
3) Add each image to the background
4) Save the modified image.

None of these is difficult:
1) Simple: Look at Image.FromFile[^]
2) Pretty simple, again, break it down:
2a) Get the text: Look at the TextBox.Text[^] property
2b) Break the text into separate characters: See String.ToCharArray[^]
2c) Create an array of Image objects, big enough to hold an image for each character - easy, but I''ll give you the code:
Dim charImages As Image() = New Image(charsInString.Length)


2d)遍历各个数组中的每个字符和每个图像-请参见
FOR循环 [ ^ ]
2e)在循环中,从磁盘读取每个字符图像-参见上面的1,但使用其他文件夹,并使用该字符标识图像文件.
3)这有点难(但不是很多)-再次,我给您一些代码-您可能需要对其进行一些修改.


2d) Loop through each character and each image in the respective arrays - see a FOR loop[^]
2e) In the loop, read each character image from teh disk - see 1 above, but use a different folder, and the character to identify the image file.
3) This is slightly harder (but not a lot) - again, I''ll give you a bit of code - you may need to modify it a bit.

Dim x As Integer = 0
Using g As Graphics = Graphics.FromImage(myBackGorundImage)
	For i As Integer = 0 To charImages.Length - 1
		g.DrawImage(charImages(i), New Point(x, 0))
		x += charImages(i).Width
	Next
End Using


4)参见 Image.Save [


4) See Image.Save[^]

Done!

I would suggest that you do each step at a time, and make sure it works before you move on to the next.
Remember that you have a full debugger available, which can help a lot in working out what is wrong!


您可能希望查看
You may wish to check out some of the links in this search.

We aren''t here to just dump code out for you. You need to do that for yourself. What we will do is help you with specific code-related issues that arise from your efforts. If you don''t show any effort, why would we volunteer our time to effort a solution for you.

Cheers.


将第一张图像放置在Panel1上.

Panel1.Image = System.Drawing.Image.FromFile(Filename1)

将一个文本框控件放置在Panel1控件内,并在图像上添加所需的文本.

放置此子SaveAsBitmap

Place the first image inside a Panel1 ontrol.

Panel1.Image = System.Drawing.Image.FromFile(Filename1)

Place a textbox control inside the Panel1 control with the text you want on the image.

Place this sub SaveAsBitmap

Public Sub SaveAsBitmap(ByVal control As Control, ByVal fileName As String)
        On Error GoTo ErrorHandel

        Dim fileExists As Boolean
        fileExists = My.Computer.FileSystem.FileExists(fileName)
        If fileExists = True Then
            My.Computer.FileSystem.DeleteFile(fileName)
        End If

        'getthe instance of the graphics from the control
        Dim g As Graphics = control.CreateGraphics()

        'new bitmap object to save the image
        Dim bmp As New Bitmap(control.Width, control.Height)
        'Drawing control to the bitmap
        control.DrawToBitmap(bmp, New Rectangle(0, 0, control.Width, control.Height))

        bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg)
        bmp.Dispose()


ErrorHandel:
        PictureBox1.Image = Nothing
        Resume Next
    End Sub



然后使用控件的名称和要将其另存为的图像的名称来调用sub.

SaveAsBitmap(Panel1,Filename1)



Then call the sub with the name of the control and the name of the image you want to save it as.

SaveAsBitmap(Panel1, Filename1)


这篇关于如何在图像上写入图像并通过vb.net编码保存输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆