delphi代码转成c++builder
proceduretxttojpeg(txt,filename:string;brush_color:tcolor;font:tfont;font_color:tcolo...
procedure txttojpeg(txt, filename: string; brush_color: tcolor; font: tfont;
font_color: tcolor; width, height: integer);
var
temp: tbitmap;
jpeg: tjpegimage;
i, j: integer;
begin
temp := tbitmap.create;
try
temp.height := height;
temp.width := width;
temp.transparent := true;
temp.canvas.brush.color := brush_color;
temp.canvas.font := font;
temp.canvas.font.color := font_color;
j := 0;
for i := 0 to form1.memo1.lines.count - 1 do
begin
j := j + 15;
temp.canvas.textout(10, j, form1.memo1.lines.strings[i]); //表示距离,top,left.
end;
temp.SaveToFile('c:\1.bmp');
finally
temp.destroy;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
txttojpeg(memo1.lines.text, savedialog1.filename + '.jpg', clwhite, Memo1.Font, clblack, memo1.width, memo1.height);
end;
end.
试过了,通不过的,请帮忙改一下吧
其实就是我想在C++BUILDER下将文本转成位图存起来 大家帮帮忙 展开
font_color: tcolor; width, height: integer);
var
temp: tbitmap;
jpeg: tjpegimage;
i, j: integer;
begin
temp := tbitmap.create;
try
temp.height := height;
temp.width := width;
temp.transparent := true;
temp.canvas.brush.color := brush_color;
temp.canvas.font := font;
temp.canvas.font.color := font_color;
j := 0;
for i := 0 to form1.memo1.lines.count - 1 do
begin
j := j + 15;
temp.canvas.textout(10, j, form1.memo1.lines.strings[i]); //表示距离,top,left.
end;
temp.SaveToFile('c:\1.bmp');
finally
temp.destroy;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
txttojpeg(memo1.lines.text, savedialog1.filename + '.jpg', clwhite, Memo1.Font, clblack, memo1.width, memo1.height);
end;
end.
试过了,通不过的,请帮忙改一下吧
其实就是我想在C++BUILDER下将文本转成位图存起来 大家帮帮忙 展开
展开全部
Delph和BCB虽是一个公司,同为VCL框架,但是毕竟是两种语言,不会像楼上说的.换成->就可以的.
现假设楼主有一定的C++基础,能使用基本的BCB6,改写如下:
1.新建一新工程,加入一Memo和一Button,控件Name为Memo1和Button1(即默认的名字)
2.向Memo1中加入任意内容,双击Button1产生单击事件
3.加入如下代码:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void txttojpeg(TMemo* Memo1,AnsiString filename,TColor brush_color,TFont* font,TColor font_color,int width, int height)
{
Graphics::TBitmap *temp=new Graphics::TBitmap();
temp->Height=height;
temp->Width=width;
temp->Transparent=true;
temp->Canvas->Brush->Color=brush_color;
temp->Canvas->Font=font;
temp->Canvas->Font->Color=font_color;
int i=0,j=0;
for (i=0;i<Memo1->Lines->Count;i++){
j = j + 15;
temp->Canvas->TextOutA(10,j,Memo1->Lines->Strings[i]);
}
temp->SaveToFile(filename);
delete temp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
txttojpeg(Memo1 ,"12.bmp", clWhite, Memo1->Font, clBlack, Memo1->Width, Memo1->Height);
}
//---------------------------------------------------------------------------
4.代码中重复的可省略,程序在BCB6 SP4下编译运行通过
现假设楼主有一定的C++基础,能使用基本的BCB6,改写如下:
1.新建一新工程,加入一Memo和一Button,控件Name为Memo1和Button1(即默认的名字)
2.向Memo1中加入任意内容,双击Button1产生单击事件
3.加入如下代码:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void txttojpeg(TMemo* Memo1,AnsiString filename,TColor brush_color,TFont* font,TColor font_color,int width, int height)
{
Graphics::TBitmap *temp=new Graphics::TBitmap();
temp->Height=height;
temp->Width=width;
temp->Transparent=true;
temp->Canvas->Brush->Color=brush_color;
temp->Canvas->Font=font;
temp->Canvas->Font->Color=font_color;
int i=0,j=0;
for (i=0;i<Memo1->Lines->Count;i++){
j = j + 15;
temp->Canvas->TextOutA(10,j,Memo1->Lines->Strings[i]);
}
temp->SaveToFile(filename);
delete temp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
txttojpeg(Memo1 ,"12.bmp", clWhite, Memo1->Font, clBlack, Memo1->Width, Memo1->Height);
}
//---------------------------------------------------------------------------
4.代码中重复的可省略,程序在BCB6 SP4下编译运行通过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询