I'm trying to display a photo depending on the BMI of the user.. So for example if your BMI is under 18.5 it will show a thumbs down.
All the images are located in my resource folder. But the image doesn't show up in the program as it should.. I've tried serveral images to see if it had something to do with the resolution. This is my code:
#FXML
private void tellUserStatus(){
date = new Date();
if (bmi<18.5){
System.out.println(dateFormat.format(date)+"User is underweight - BMI is under 18.5");
BmiStatusMessage.setVisible(true);
BmiStatusMessage.setText("You are underweight");
File underweight= new File("underweight-thumbsdown.png");
Image image = new Image(underweight.toURI().toString());
BmiConclusion.setVisible(true);
BmiConclusion.setImage(image);
}
}
BmiStatusMessage is a Label, and BmiConclusion is an ImageView. They are both linked with the fxml file.
Related
This is example on site Oracle and they say this working.
// load the image
Image image = new Image("file_name.png");
// simple displays ImageView the image as is
ImageView iv1 = new ImageView();
iv1.setImage(image);
On site is picture result code. But it did not work for me. I see exception
java.lang.IllegalArgumentException: Invalid URL or resource not found.
Probably outdated. Try this.
File selectedFile = new File("yourfile.png");
String filePath = selectedFile.getAbsolutePath();
Image image = new Image(selectedFile.toURI().toURL().toString());
ImageView iv1 = new ImageView();
iv1.setImage(image);
My code is:but I can't find image in QWidget. What can I do if i want to show the image ? And what's wrong with my code?
QTtest::QTtest(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout * m_viewLayout = new QHBoxLayout();
this->setLayout(m_viewLayout);
QHBoxLayout * showLayout = new QHBoxLayout();
QHBoxLayout * btnLayout = new QHBoxLayout();
m_viewLayout->addLayout(showLayout);
m_viewLayout->addLayout(btnLayout);
widget1 = new QWidget();
showLayout->addWidget(widget1);
QPixmap image("C:\\Users\\zhq\\Desktop\\1.png");
QPainter painter(widget1);
painter.drawPixmap(QPoint(0,0),image);
widget2 = new QWidget();
showLayout->addWidget(widget2);
QPushButton * btn = new QPushButton("btn");
btnLayout->addWidget(btn);
showLayout->addStretch();
}
There's a couple of thing wrong with your code.
Assuming that the image is loaded correctly, you should paint the image in the void QWidget::paintEvent(QPaintEvent * event) of your widget. Do not paint outside of paint events. Also, as you're currently doing it, the image will be overwritten the next time the widget updates/reapints itself anyway.
You might consider going an easier route and use a QLabel in your layout instead of widget1. You can then call QPixmap::fromImage() to convert the image to a pixmap and QLabel::setPixmap() on the label to display your image.
I'm opening a new flex project in Flash builder and I'm trying to make an interface with 3 buttons, "cat", "dog", and "bird." When each of the buttons are pressed, I would like an image box on the bottom of the screen to fill in with the appropriate animal's image.
I'm having a lot of trouble figuring out how to display an image in AS3. Can anyone help point me in the right direction?
One of the simplest way would be, if you don't mind your swf to embed the three images:
embed code
[Embed(source="/../assets/cat.jpg")]
static private const Cat:Class;
[Embed(source="/../assets/dog.jpg")]
static private const Cat:Class;
[Embed(source="/../assets/bird.jpg")]
static private const Cat:Class;
container initialization
private var imageBox:Sprite = new Sprite;
// initialize imagebox position/chose parent here, for instance:
container.addChild(imageBox);
cat button click handler
imageBox.removeChildren();
imageBox.addChild(new Cat);
dog button click handler
imageBox.removeChildren();
imageBox.addChild(new Dog);
bird button click handler
imageBox.removeChildren();
imageBox.addChild(new Bird);
I'm assuming your project has "assets" & "src" directories, containing respectively your images and your as3 code
I have a gallery application that needs to zoom and pan. Instead of using default imageview , I found a sample touchmageview on internet and copied it. I called my images with TouchImageView and now i can zoom and pan the images that I called from my drawable folder. Then I added gallery to my project. Now the problem is that I can not fit the images to the screen.When I use scaletype.center then it fits the image to the screen but now zoom and pan features are not working. This is my gallerylistener ;
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(Display.this, "Your selected position = " + position, Toast.LENGTH_SHORT).show();
// show the selected Image
img.setScaleType(ScaleType.CENTER_INSIDE);
img.setImageResource(Imgid[position]);
}
});
As you see , if I add img.setScaleType(ScaleType.CENTER_INSIDE); then the TouchImageView class doesn't work and I am not able to zoom and pinch and pan etc.. It only display the image. When I delete this code , then I can zoom but then when I change the picture to another one , the new one has the previous image's size. But I want to fit them to the center. Is there any way to reset the scaletype before calling the new image ?
By the way I have only one imageview in xml.
There is a similar question on this link but the solution did not work for me.
how to get setScaleType(ImageView.ScaleType.FIT_CENTER) effect using setScaleType(ImageView.ScaleType.MATRIX)
HI all,
I wnt to develop an ImageViewer using qt. I m trying to resize big images by scaling them. My problem is , when i change the screen orientation some part of the image gets clipped and also if i open the image in landscape mode, by default the size of image remains small even when i change back to portrait mode. What am i Doin wrong?
Please help me out. Heres the code dat i hv written
ImageViewer::ImageViewer()
{
setAttribute(Qt::WA_DeleteOnClose);
QAction *back = new QAction(this);
back->setText(QString("Back"));
connect(back,SIGNAL(triggered()),this,SLOT(close()));
back->setSoftKeyRole(QAction::PositiveSoftKey);
addAction(back);
imageLabel = new QLabel();
imageLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
imageLabel->setAlignment(/*Qt::AlignLeft|*/Qt::AlignCenter);
QWidget *widget = new QWidget;
layout=new QStackedLayout();
layout->addWidget(imageLabel);
widget->setLayout(layout);
setCentralWidget(widget);
}
void ImageViewer::showImage(QString filePath)
{
QImageReader reader;
reader.setFileName(filePath);
QSize imageSize = reader.size();
imageSize.scale(size(), Qt::KeepAspectRatio);
reader.setScaledSize(imageSize);
QImage image = reader.read();
imageLabel->setPixmap(QPixmap::fromImage(image));
imageLabel->adjustSize();
}
You should re-implement QLabel's resizeEvent or install event filter to it and handle QResizeEvent there
The content of showImage method should go to handler of a resize event.
Currently you are using size() of ImageViewer widget (which seems to be derived from QMainWindow), it's better to use imageLabel.size(); or the best QResizeEvent::size() as this will prevent a problem if you will change UI layout in future.