天嵌 ARM开发社区

 找回密码
 注册
查看: 5537|回复: 21

关于加载图片

[复制链接]
liyayao 发表于 2010-9-10 12:56:36 | 显示全部楼层 |阅读模式
我写了一个小程序是QTOPIA的

在里面有画的函数

void hua::paintEvent(QPaintEvent *)
{
  QPainter painter(this);
  QImage image;
  //image.load("root/Documents/CC.png"); //这句能显示图片
   image.load("root/Documents/DD.jpeg");//这句不能显示图片
  painter.drawImage(0,0,image);
}

就这个函数 为什么就对jpeg的没反应,对png有反应
难到不支持jpeg,那为什么系统自带的pictures就能显示jpeg的相片呢
求版主帮忙。我这个程序就这么简单的,没别的,编译通过了的
天嵌_support1 发表于 2010-9-10 14:18:23 | 显示全部楼层
1# liyayao

你的部分代码,没法看出问题的所在。我给你的建议:

1. 用 QImage::isNull () 看看你的图片加载成功没有。
2. Image.load() 的时候指定一下格式是 JPEG。
3. 实在不行你就调用它的转换图片格式函数来转换一下吧
 楼主| liyayao 发表于 2010-9-10 16:00:28 | 显示全部楼层
2# embedsky_lxt

帮我看看版主
就只有PNG行
JPG JPEG 都不行

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| liyayao 发表于 2010-9-12 11:52:38 | 显示全部楼层
2# embedsky_lxt
  1. /****************************************************************************
  2. ** Form interface generated from reading ui file 'first.ui'
  3. **
  4. ** Created: Mon Aug 9 13:16:40 2010
  5. **      by:  The User Interface Compiler (uic)
  6. **
  7. ** WARNING! All changes made in this file will be lost!
  8. ****************************************************************************/
  9. #ifndef FIRST_H
  10. #define FIRST_H

  11. #include <qvariant.h>
  12. #include <qwidget.h>
  13. class QVBoxLayout;
  14. class QHBoxLayout;
  15. class QGridLayout;
  16. class QLineEdit;
  17. class QPushButton;
  18. class QTextBrowser;
  19. class QIODevice;
  20. class QTCore;
  21. class QLabel;

  22. class first : public QWidget
  23. {
  24.     Q_OBJECT

  25. public:
  26.     first( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
  27.     ~first();
  28.    

  29. protected:
  30.     virtual void paintEvent(QPaintEvent* );
  31. public slots:
  32.    

  33. };

  34. #endif // FIRST_H


  35. /****************************************************************************
  36. ** Form implementation generated from reading ui file 'first.ui'
  37. **
  38. ** Created: Mon Aug 9 13:16:40 2010
  39. **      by:  The User Interface Compiler (uic)
  40. **
  41. ** WARNING! All changes made in this file will be lost!
  42. ****************************************************************************/
  43. #include "first.h"
  44. #include <qlabel.h>
  45. #include <qiodevice.h>
  46. #include <qlineedit.h>
  47. #include <qpushbutton.h>
  48. #include <qtextbrowser.h>
  49. #include <qlayout.h>
  50. #include <qvariant.h>
  51. #include <qtooltip.h>
  52. #include <qwhatsthis.h>
  53. #include "serial_test.h"
  54. #include <fcntl.h>
  55. #include <termios.h>
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <sys/types.h>
  59. #include <sys/stat.h>
  60. #include <errno.h>
  61. #include <ctype.h>
  62. #include <string.h>
  63. #include <time.h>
  64. #include <unistd.h>
  65. #include <qpainter.h>
  66. #include <qtextstream.h>
  67. #include <qdatastream.h>
  68. #include <qfile.h>
  69. #include <qimage.h>

  70. first::first( QWidget* parent,  const char* name, WFlags fl )
  71.     : QWidget( parent, name, fl )
  72. {
  73.     if ( !name )
  74.         setName( "first" );
  75.     resize( 584, 480 );
  76.     setCaption( tr( "EmbedSky_First_Qt_Program" ) );
  77.    
  78. }

  79. /*  
  80. *  Destroys the object and frees any allocated resources
  81. */
  82. first::~first()
  83. {
  84.     // no need to delete child widgets, Qt does it all for us
  85. }

  86. void first::paintEvent(QPaintEvent *)
  87. {
  88.      
  89.    

  90.      QPainter painter(this);
  91.      
  92.      QImage image;
  93.         //image.load("root/Documents/kk.png");//true
  94.         image.load("root/Documents/DD.jpeg","jpeg");//false
  95.         //image.load("root/Documents/tt.jpg","jpg");//false

  96.      painter.drawImage(0, 0, image);

  97. }




  98. #include "first.h"
  99. #include <qapplication.h>
  100. #include <qtopia/qpeapplication.h>


  101. QTOPIA_ADD_APPLICATION("first",first)

  102. QTOPIA_MAIN
复制代码
testh 发表于 2010-9-12 11:55:54 | 显示全部楼层
你换QPixmap加载试试,我用QPixmap可以显示jpg的图片
 楼主| liyayao 发表于 2010-9-12 14:49:49 | 显示全部楼层
5# testh

郁闷,咋我就不行呢,QPixmap也只能用PNG ,jpg,jpeg也不行
 楼主| liyayao 发表于 2010-9-12 14:51:38 | 显示全部楼层
有没有人能帮我试试,看看是不是我的板的移值出现问题,还是没有加入什么什么库之类的事呢,。。。。
天嵌_support1 发表于 2010-9-13 11:02:13 | 显示全部楼层
7# liyayao


你用的是什么开发工具呢,我用 QCreator ,一编译一百个错误。
 楼主| liyayao 发表于 2010-9-13 18:26:20 | 显示全部楼层
8# embedsky_lxt
我用的是4.3.3的
都天嵌提供的
环境是QTE的setARM_QpeEnv的都是天嵌提供的
我都是直接编译的 用make 命令
没有用过QCreator编译QT2
QCreator我是用来编译QT4的
天嵌_support1 发表于 2010-9-14 12:15:37 | 显示全部楼层
9# liyayao


我建议你用新的开发工具QCreator吧。里面的examples 你能都学一学,那就不错了
 楼主| liyayao 发表于 2010-9-14 18:06:34 | 显示全部楼层
10# embedsky_lxt

QCreator 我是经常用的,但我目前也只是用来编译QT4,
我现在是按你们的教程一步一步来学习的
现在这简单的程序搞到我郁闷,我感觉是没有错的,这我在电脑上的QT是能显示图片,移植到板上就
不行。
 楼主| liyayao 发表于 2010-9-14 18:16:23 | 显示全部楼层
这个我是用在Qtopia上的,QCreator能编译吗?
天嵌_support1 发表于 2010-9-14 19:28:07 | 显示全部楼层
12# liyayao


不行,编译没有通过
testh 发表于 2010-9-15 06:30:47 | 显示全部楼层
QPainter painter(this);
     
     QImage image;
        //image.load("root/Documents/kk.png");//true
        image.load("root/Documents/DD.jpeg","jpeg");//false
        //image.load("root/Documents/tt.jpg","jpg");//false
    painter.begin(this);
     painter.drawImage(0, 0, image);
   painter.end();

你在代码中加上上面蓝色的那两句试试
testh 发表于 2010-9-15 06:33:51 | 显示全部楼层
还有就是你的这个目录对吗?
root/Documents/DD.jpeg
上面的这个是绝对路径?还是应该是下面的?
/root/Documents/DD.jpeg
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-27 23:24 , Processed in 1.030313 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表