关于GDI+加载图片的问题

awfymwvf 2011-11-16 04:02:05
在VC中使用GDI+来加载图片,例如
Image image(L"image\\DaLu4.png");

我现在想把引号中的换成一个变量。这个变量就是图片的路径。能实现吗?

...全文
274 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnzlk 2011-11-19
  • 打赏
  • 举报
回复
northcan 2011-11-19
  • 打赏
  • 举报
回复

CString strPath = 获取的文件名;
Image image(strPath );


8楼已经给出答案了,楼主你得自己仔细思考一下啊。
向立天 2011-11-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 awfymwvf 的回复:]
楼上的朋友。你这种方法不是相当于还是没有用上变量吗。这个变量应该是用打开对话框获取到的图片文件名。如szfilename这样的
[/Quote]strPaht不是变量么?
难道你不会尝试转换一下么?
awfymwvf 2011-11-18
  • 打赏
  • 举报
回复
是不是我这个是不可能完成的任务啊。兄弟们。帮助我啊
awfymwvf 2011-11-17
  • 打赏
  • 举报
回复
楼上的朋友。你这种方法不是相当于还是没有用上变量吗。这个变量应该是用打开对话框获取到的图片文件名。如szfilename这样的
向立天 2011-11-17
  • 打赏
  • 举报
回复
这样不行么
CString strPaht = L"image\\DaLu4.png";
Image image(strPaht);
awfymwvf 2011-11-17
  • 打赏
  • 举报
回复
谢谢兄弟们的回答,

但关键是这个L后面加变量要如何写呢?

我用Image image(L&szfilename);这样通不过啊
awfymwvf 2011-11-17
  • 打赏
  • 举报
回复
有没有知道这个用法的啊?
monk_CD 2011-11-16
  • 打赏
  • 举报
回复
如果在UNICODE下有错误 , 就换成多字节库试试!


我看你加了L! 你试试!
  • 打赏
  • 举报
回复
CString
hnzlk 2011-11-16
  • 打赏
  • 举报
回复
没有问题
peterormike 2011-11-16
  • 打赏
  • 举报
回复
MSDN上有示例代码。复制过来你看看:
Bitmap image1;

private void Button1_Click(System.Object sender, System.EventArgs e)
{

try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);

int x, y;

// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}

// Set the PictureBox to display the image.
PictureBox1.Image = image1;

// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();

}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
awfymwvf 2011-11-16
  • 打赏
  • 举报
回复
楼上的兄弟,怎么实现啊?
peterormike 2011-11-16
  • 打赏
  • 举报
回复
动态加载?应该能吧。

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧