Hello,
I apologize for posting in various forum.
1) Have you tried using an extension for the image?
I tried to use extension "jpg". And I test with other type images as "png" and "gif"
2) How do you "load a file image and convert it to thumbnail"? Is that an external process?
I use a java program to convert file image to thumbnail. I use the code that I found in document "BP107: Ten Lines Or Less Interesting Things You Can Do In Java With Minimal Code". You can see in "http://es.slideshare.net/panagenda/bp107-ten-lines-or-less-interesting-things-you-can-do-in-java-with-minimal-code"
3) Is the "random file name" that random file name Notes automatically generate for duplicate attachments with the same name as an existing file? I think it is a 8 character file name...
I have tested the file name "photo", "photo.jpg".
4) How is the object img declared and initialized? Yes, it's.
I can see the image files in disk and open them.
5) Can you post more code?
I write a short example:
public static byte[] createThumbnail(InputStream in, float size)throws IOException {
ByteArrayOutputStream baos=null;
String msg="";
try {
if (in==null)
_log.error("is null");
BufferedImage bi = ImageIO.read(in);
float scale = Math.min(size/bi.getHeight(), size/bi.getWidth());
BufferedImage thumb = new BufferedImage(bi.getWidth(),
bi.getHeight(), bi.getType());
AffineTransformOp op = new AffineTransformOp
(AffineTransform.getScaleInstance(scale, scale),
AffineTransformOp.TYPE_BICUBIC);
thumb = op.filter(bi, thumb);
thumb = thumb.getSubimage(0, 0,(int)(bi.getWidth()*scale), (int)(bi.getHeight()*scale));
baos = new ByteArrayOutputStream();
ImageIO.write(thumb, "jpg", baos);
_log.debug("Convert image to thumb");
return baos.toByteArray();
}catch (Exception e) {
msg="Some error to convert he image to thumb "+e.getMessage() ;
_log.error(msg,e);
e.printStackTrace();
}
return baos.toByteArray();
}
public static void ConvertThumbnail(String path,String path2) {
/
OutputStream targetFile = null;
try {
targetFile = new FileOutputStream(path);
InputStream is = new BufferedInputStream(new FileInputStream(path));
_log.debug("I read the image file "+path);
if (is==null)
_log.error("is null");
byte[] thum;
try {
thum = createThumbnail(is, 50);
_log.debug("Try to convert image to thumbnail and convert it to file "+path2);
OutputStream targetFile2 = new FileOutputStream(path2);
targetFile2.write(thum);
targetFile2.close();
} catch (IOException e) {
_log.error("Error to convert the thumbnail "+path2,e);
e.printStackTrace();
}
} catch (FileNotFoundException e) {
_log.error("Error to load the image "+path,e);
e.printStackTrace();
}
}
public static void FillDocumentPABLibretaPersonal(Session sesion,String path) throws NotesException {
Document doc=null;
Database db=sesion.getDatabase("TEST//ACME ", "ejemplos\\miembrospab7.nsf");
if (db != null) {
doc = db.createDocument();
doc.replaceItemValue("form","Person");
doc.replaceItemValue("type","Person");
String lastname="Sanchez Romero";
String firstname="Paco";
doc.replaceItemValue("lastname",lastname);
doc.replaceItemValue("Firstname",firstname);
doc.replaceItemValue("Fullname",firstname+" "+lastname);
RichTextItem img = null;
img = (RichTextItem) doc.getFirstItem("Photo");
if (img !=null) {
_log.info(".getFirstItem Tiene campo Photo");
}else {
_log.info(".getFirstItem No tiene campo Photo");
if (doc.hasItem("Photo"))
_log.info("hasItem Ya tiene campo Photo");
else {
img = doc.createRichTextItem("Photo");
_log.info("hasItem. Creamos el campo Photo");
}
}
img.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, path, "ContactPhoto");
doc.save();
_log.info("Document save");;
}
}
String path="c:\\basura\\photos\\ContactPhoto.jpg";
String path2="c:\\basura\\pfotos\\ContactPhoto2.jpg";
I tried this
img.embedObject(EmbeddedObject.EMBED_OBJECT,"", path, "ContactPhoto");
but it shows
NotesException: Could not create OLE file from C:\Windows\TEMP\notesB7FA22\40101D58.TMP
It the field is only a "Rich Text" I see a image file attach to field. The problem is with "Rich Text lite" field.
thank very much
Regards