i am developing an android app and trying to convert a RasterImage to Bitmap Image in order to draw a line with given points. but i am getting an exception on conversion. i am using LEADTOOLS DICOM SDK Version 18 For this. below is the code i am using
private void drawingfunction(float x, float y, float xend, float yend, int color) {
try{
RasterImage _loadedImage;
RaterImageViewer secondviewer;
Bitmap newpic;
newpic=RasterImageConverter.convertToBitmap(_loadedImage2, ConvertToImageOptions.NONE.getValue());
newpic = Bitmap.createBitmap(_loadedImage2.getWidth(), _loadedImage2.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(newpic);
c = new Canvas(newpic);
secondviewer.draw(c);
Paint p = new Paint();
p.setColor(color);
c.drawLine(x, y, xend, yend, p);
secondviewer.setImageBitmap(newpic);
}
catch(Exception ex)
{
Toast.makeText(getApplicationContext(),ex.toString(),Toast.LENGTH_SHORT).show();
}
}
We tested code similar to yours in the ViewerDemo shipped with our v18 Android toolkit, and it did not show a similar problem. If you'd like to try our test, start with this project: LEADTOOLS_Android_18\Examples\Android\ViewerDemo Then modify the setImage() function in the file ViewerDemoActivity.java to become like this:
private void setImage(RasterImage image) {
try {
int bpp = image.getBitsPerPixel();
RasterByteOrder order = image.getOrder();
Bitmap newpic=RasterImageConverter.convertToBitmap(image, ConvertToImageOptions.NONE.getValue());
newpic = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(newpic);
c = new Canvas(newpic);
mViewer.draw(c);
Paint p = new Paint();
p.setColor(0xFFFF0000);
c.drawLine(20, 20, 200, 200, p);
mViewer.setImageBitmap(newpic);
} catch(Exception ex) {
Messager.showError(this, ex.getMessage(), "");
}
}
We tried different images, including color and 16-bit grayscale Dicom images, and they all worked. If the problem is still active at your side, email the actual image that triggers it to LEAD support and provide more details about the project you used for testing.