package ksiazka.kucharska;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.swing.ImageIcon;
|
|
|
|
public class CB_Model {
|
|
private int id;
|
|
private String name;
|
|
private String ingredients;
|
|
private String description;
|
|
private String tags;
|
|
private ImageIcon img;
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
public String getIngredients() {
|
|
return ingredients;
|
|
}
|
|
public void setIngredients(String ingredients) {
|
|
this.ingredients = ingredients;
|
|
}
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
public String getTags() {
|
|
return tags;
|
|
}
|
|
public void setTags(String tags) {
|
|
this.tags = tags;
|
|
}
|
|
public ImageIcon getImage() {
|
|
return img;
|
|
}
|
|
public void setImage(ImageIcon img) {
|
|
this.img = img;
|
|
}
|
|
public byte[] getImageArr() {
|
|
try {
|
|
BufferedImage bImg = new BufferedImage(img.getIconWidth(), img.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
|
|
|
bImg.getGraphics().drawImage(img.getImage(), 0,0, null);
|
|
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
|
|
//Buffered Image -> Byte Stream
|
|
ImageIO.write( bImg, "png", bStream );
|
|
bStream.flush();
|
|
//Byte Stream -> Byte Array
|
|
byte [] arr = bStream.toByteArray();
|
|
bStream.close();
|
|
|
|
return arr;
|
|
}
|
|
catch (IOException e) {
|
|
System.err.println("Blad przy wstawianiu przepisu");
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public CB_Model() {}
|
|
public CB_Model(int id, String name, String ingredients, String description, String tags, ImageIcon img) {
|
|
this.id = id;
|
|
this.name = name;
|
|
this.ingredients = ingredients;
|
|
this.description = description;
|
|
this.tags = tags;
|
|
this.img = img;
|
|
}
|
|
|
|
|
|
}
|