|
Re: Painting and drawing problem using GC in RAP. [message #1823157 is a reply to message #1823071] |
Fri, 20 March 2020 13:10 |
Chandra Kyama Messages: 9 Registered: February 2020 |
Junior Member |
|
|
Solution:
Please refer below Process steps:
1. Written the customized CustomBase64Image class which maintainig the base64 image string and zoom properties.
2. Introduced the ImageViewerComposite.java which creates the custom browser composite with specified image pattern.
3. Customized methods zoomout, zoomin, rotate and updateImageViewer to update image processing in browser composite.
4. Preparing the base64Image image based on ImageData which internally uses ByteArrayOutputStream and ImageLoader.
5. No more using ImageCanvas class and its supportive methods of ImageUIUtil methods.
6. Added java docs to respective changes and please refer accordingly.
Source code:
public class CustomBase64Image {
private String imageSource = null;
private int zoom = 5;
public CustomBase64Image(String imageSource, int zoom) {
super();
this.imageSource = imageSource;
this.zoom = zoom;
}
public String getImageSource() {
return imageSource;
}
public void setImageSource(String imageSource) {
this.imageSource = imageSource;
}
public int getZoom() {
return zoom;
}
public void setZoom(int zoom) {
this.zoom = zoom;
}
}
public class ImageViewerComposite {
private static final String IMAGE_PATTERN = "<html><body><div style=\"text-align: center;\"><img src=\"data:image/png;base64,{0}\" style=zoom:{1}; ></img></div></body></html>";
private CustomBase64Image base64Image = null;
private final Browser imageViewer;
public ImageViewerComposite(final Composite parent) {
imageViewer = createViewerComposite(parent);
}
/**
* This method is displaying the base64 image into browser based on ImagePattern.
*
* @param customImage is the argument type of CustomBase64Image.
* which internally binds the image source and zoom percentage.
*
*/
public void updateImageViewer(final CustomBase64Image customImage) {
this.base64Image = customImage;
final String zoomPercentage = base64Image.getZoom() + "%";
String format = MessageFormat.format(IMAGE_PATTERN, base64Image.getImageSource(), zoomPercentage);
imageViewer.setText(format);
}
/**
* Current image page should be zoomed out and display into browser upon zoom value.
*
* @return zoom value to the caller method.
*/
public int zoomOut() {
if (base64Image.getZoom() > 5)
base64Image.setZoom(base64Image.getZoom() - 5);
updateImageViewer();
return base64Image.getZoom();
}
/**
* Current image page should be zoomed in and display into browser upon zoom value.
*
* @return zoom value to the caller method.
*/
public int zoomIn() {
if (base64Image.getZoom() >= 5)
base64Image.setZoom(base64Image.getZoom() + 5);
updateImageViewer();
return base64Image.getZoom();
}
/**
* It update the image size based on the zoom value and image source.
*/
private void updateImageViewer() {
final String zoomPercentage = base64Image.getZoom() + "%";
String format = MessageFormat.format(IMAGE_PATTERN, this.base64Image.getImageSource(), zoomPercentage);
imageViewer.setText(format);
}
/**
* It creates the browser composite and layout.
* @param parent argument is passing value of specified composite.
* @return Returns the Browser object with layout data.
*/
private Browser createViewerComposite(Composite parent) {
final Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
final Browser browser = new Browser(composite, SWT.BORDER);
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
composite.layout();
return browser;
}
}
private void initImages() { //KEC-21690
model.getImageIndexBean().getImagePageInfoBeans();
sourceImages = model.getImageIndexBean().getSourceImages();
for (ImageData data : sourceImages) {
CustomBase64Image image = new CustomBase64Image(convertToBase64Image(data), INITIAL_ZOOM);
base64Images.add(image);
}
imageViewerComposite.updateImageViewer(base64Images.get(0));
}
/**
* This method converts image data to base64 string content.
* <p> Converting image data to byteArrayOutputStream data which internally converting byte stream data to base64 string data by using @Code ImageLoader class.
*
* @see ByteArrayOutputStream
* @see ImageLoader
* @see Base64.getEncoder()
*
* @param imageData type of ImageData.
*
*/
public String convertToBase64Image(ImageData imageData) { //KEC-21690
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[]{imageData};
loader.save(out, SWT.IMAGE_PNG);
return Base64.getEncoder().encodeToString(out.toByteArray());
}
Please refer above solution to fix display functionality in Latest RAP.
Thanks & Regards
Chandra Shaker Kyama
[Updated on: Fri, 20 March 2020 13:11] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03605 seconds