c++ 解析eps文件

eps文件是可以通过记事本打开的



其中BoundingBox表示的是eps文件的大小,(0,0)表示的是左下角的坐标,(324 ,226)表示的是右上角的坐标。

坐标的大小表示单位是像素,所以我们要转化为英寸,再转化为mm输出,看你个人需求了,我这次用的mm输出。eps

文件的编码方式是ASCii码。


通过编程获得.eps文件的高度跟宽度。


vs2010下跑通代码

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;


template<class out_type,class in_value>
out_type convert(const in_value & t) 
{
	stringstream str;
	str<<t;
	out_type result;
	str>>result;
	return result;
}

template<class out_type,class in_value>
out_type convert(const in_value & t,bool bISWSring) //转wchar,wstring要用到这个
{
	wstringstream str;
	str<<t;
	out_type result;
	str>>result;
	return result;
}


int main()
{
	string filename;
    cin>>filename;
	string text;
	string str;
	fstream in(filename.c_str());
	int nFlag;

	if(!in)
	{
		cout<<"error"<<endl;
	}


    for (int i=0;i<10;i++) //获取Box那一行字符串
    {
        getline(in,text);
	    if(text[2]=='B'&&text[3]=='o')
		{
		     break;
		}
	}

	string box[4];
	int t=15;
	for(int i=0;i<4;i++)//提取四个坐标
	{
		int j;
	    for(j=t;j<text.length();j++)
	    {
			if(text[j]==' ')
			{
				 break;
			}
			box[i].push_back(text[j]);
	    }
		 t=j+1;
	}

	for(int i=0;i<4;i++)
	{
       cout<<box[i]<<endl;
	}

	double a[4];

	for(int i=0;i<4;i++)
	{
		a[i]=convert<double>(box[i]);
	}

	for(int i=0;i<4;i++)
	{
		cout<<a[i]<<endl;
	}

	double width,height;

	width=(a[2]-a[0])/72*25.4;
	height=(a[3]-a[1])/72*25.4;

	cout<<"width:"<<width<<endl;
	cout<<"height"<<height<<endl;
    
	cout<<text<<endl;


	return 0;
     
}



这个程序也用到了我原来写的任意转化数据类型的模板


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值