I'm currently trying to make an android dicom app
Following code opens pictures drom res/drawable in "ussual" image formats, but it doesn't work with .dcm
public class BitmapView extends View
{
public BitmapView(Context context) {
super(context);
}
#Override
public void onDraw(Canvas canvas) {
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bmp, 10, 10, null);
}
}
in the main activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new BitmapView(this));
}
thanks in advance!
Dicom is a kind of generic container. Inside a Dicom file you can find a huge variety of image formats. From grayscale ones to RGB, from single frame to multiframe ones, with pixel value ranges not in the ordinary 8 bit (24/32 in RGB/RGBA) but also in 12 or 16 bit grayscales.
Dicom files include many elements (fields) indicating the type of the contents and even how such contents should be presented. It is not as simple as converting the Dicom image to BMP.
If you are retrieving Dicom images from a PACS, I would suggest using WADO service. This way, you can obtain Jpeg images (the results of having applied a presentation state to the contents of the Dicom file).
The other option is to use some utility to convert the Dicom file to a more conventional image format. There are some excellent open source tools, such as dcmj2pnm, from the DCMTK toolkit.
Dicom images are not recognized by Android and therefore you cannot open them using a BitmapFactory object.
Recently Imebra has been extended with Java wrappers that call the Imebra native code and comes with a pre-built JAR so you don't have to deal with JNI compilation.
In addition to the 2 options mentioned by jap1968 and Paolo, which are both good but require using some method for converting the image on a different platform then viewing it on the Android device and an internet connection, you can actually view the Dicom file itself on the Android device directly if you use a library that supports DCM and its different sub-types. One such toolkit has a free demo application on Google Play here:
https://play.google.com/store/apps/details?id=leadtools.datasetdemo
Related
I have made a custom keyboard that allows users to send GIFs/Images.
Currently, whenever the user taps on a ImageView, the following code runs. It checks whether the drawable inside the ImageView is animated (i.e - the image is a GifDrawable) and if not, it casts it to a BitmapDrawable. context.contentComitter.commit() is responsible for turning the casted drawables into files that can be read by other apps.
if(holder.imageView.drawable is GifDrawable) {
context.contentCommitter.commitGifDrawable(holder.imageView.drawable, fileName)
} else {
context.contentCommitter.commitBitmapDrawable(holder.imageView.drawable as BitmapDrawable, fileName)
}
The problem is - I'm getting the following crash for certain images on Samsung Galaxy S9s only:
Fatal Exception: java.lang.ClassCastException
android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
The solution seems to be simple - just perform another check for whether holder.imageView.drawable is a VectorDrawable, and if so, extract the Bitmap and write it to a file.
However, the problem is that the VectorDrawable source seems to be a GIF file, instead of a static image. This is confusing because the methods in the VectorDrawable documentation indicate that it is only used to store static images.
Is it possible for a VectorDrawable to contain animated images (i.e - GIFs), or do VectorDrawables only contain static images?
Here is the image database: https://github.com/vedantroy/Image-Database
There are the Bitmap for Android and UIImage for iOS. Is there a way to display both somehow in the Xamarin Forms Image control?
Obviously I need the Dependency Service. I will have two implementations that create either a bitmap or an uiimage using some source, but how do I bring those two products together to a single forms control? Both Android and iOS methods have to return something, that the image control can understand and display. I don't know what that might be.
Edit: I look for a way where I don't use storage space, if possible.
Edit2:
I tried Jasons suggestion and it works fine.
I create a bitmap in the Android project and return a MemoryStream object:
MemoryStream stream = new MemoryStream();
newImage.Compress(Bitmap.CompressFormat.Png, 0, stream);
return stream;
Then I consume it in my Xamarin.Forms Image control:
var stream = DependencyService.Get<ICrossPlatformImageProcesor>().Combine_Images(imagePath);
stream.Position = 0;
img_ImageView.Source = Xamarin.Forms.ImageSource.FromStream(() => stream);
I will have two implementations that create either a bitmap or an uiimage using some source, but how do I bring those two products together to a single forms control?
You can simply use Image Control of xamarin forms, images can be loaded specifically for each platform, or they can be downloaded for display.
For more information, you can refer to Working with Images.
I look for a way where I don't use storage space, if possible.
I'm not quite understand this, if you mean don't use memory, then I think it is not possible. If you mean your images are not saved in storage, then possibly you have an URL address on internet of your images?
Anyway, Image control in Xamarin.Forms support image source form ImageSource instance, file, Uri, and resources, to load image from uri, you can simply code like this:
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
I have an app that should deploy for few different costumers.
For each costumer I want to allow different coloring and resources.
Are there any ways to enable the app to load resources and configurations from the internet on startup, and then using them on the app.
I know I can use Google Tag Manager for loading configuration values from the internet. Is there some platform I can use for doing something similar for Drawable resources?
You'll need to download the remote resources to the SD card. Then you can create drawables on the fly with:
Drawable d = Drawable.createFromPath(new File(Environment.getExternalStorageDirectory(), "yourDownloadedBackground.png").getAbsolutePath());
and then set the layout background with setBackGroundDrawable() or setBackGround(), the latter only if you're targetting API 16 or more.
The other way, is to put webviews instead of the images in your layout. This will allow you to load remote images, local files and HTML snippets. Put a webview in your layout and try this:
android.webkit.WebView v = (android.webkit.WebView) findViewById(R.id.webView1);
v.loadUrl("http://developer.android.com/assets/images/dac_logo.png");
You can use color filters, see this
Modifying the color of an android drawable
http://blog.syedgakbar.com/2012/07/changing-color-of-the-drawable-or-imageview-at-runtime-in-android/
int color=Color.rgb(colorR, colorG, colorB);
public static BitmapDrawable changeColor(Bitmap bitmap, Context context, int color){
Bitmap bitmapCopy = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas c = new Canvas(bitmapCopy);
Paint p = new Paint();
p.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
c.drawBitmap(bitmap, 0, 0, p);
return new BitmapDrawable(context.getResources(),bitmapCopy);
}
Just be sure thats the filter you want
Consider the implications of this: if you start this application on a non-internet connected device, it will still need a local cache of drawables. If your customers want a tight user experience, do you really want to be dependent upon a remote source to load the UI of your application?
Perhaps your best (though less extensible) solution would be to create multiple APKs, one for each customer. For "a few different customers", this is probably simpler than hosting UI components. For large numbers of customers, then you might start thinking about more creative solutions.
EDIT: please take a look at this answer for some productive ideas on how to efficiently manage multiple packages.
Background
We have just swapped to the UIL library, which seems fantastic. Unfortunately we have to support CMYK images (against our will) and have attempted to modify an existing ImageDecoder called BaseImageDecoder.
The code for this can be found here. http://pastebin.com/NqbSr0w3
We had an existing AsyncTask http://pastebin.com/5aq6QrRd that used an ImageMagick wrapper described in this SO post (Convert Image byte[] from CMYK to RGB?). This worked fine before in our setup.
The Problem
The current decoder fails to load the cached image from the file system and this results in a decoding error. We have looked through the source code and believe we are using the right functions. We also thought that adding our extra level of decoding at this point in the process was ideal, as the image may have been resized and stored on the file system.
File cachedImageFile = ImageLoader.getInstance().getDiscCache().get(decodingInfo.getImageUri());
if (!cachedImageFile.exists()) {
Log.v("App", "FILE DOES NOT EXIST");
return null;
}
The above lines always return that the file does not exist.
The Question
Are we incorrect to process our CMYK images at this point, and if not why can't we get the image from the cache on file system?
I am trying to load .obj files into an Android project with LibGDX. The files have no texture file, but include materials in .mtl files. I'm using the latest official nightly, and rendering the object file only results in the object appearing white. How do I get the ObjLoader to use the .mtl file?
#Override
public void create() {
objLoader = new ObjLoader();
model = objLoader.loadObj( Gdx.files.internal("data/obj.obj"), true);
}
#Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
model.render();
batch.end();
}
This is how the code to render the object is called.
Here is a link to the ObjLoader class
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/wavefront/ObjLoader.java
What am I doing wrong? And why won't it load the .mtl file? From what I can understand, it should load a .mtl file that's in the same folder and same name as the .obj file.
EDIT
I have messed around a bit, putting some lines into the ObjLoader class to log what it is and isn't loading. It looks like it's loading the mtl file, and assigning each mtl to a Material instance, and it also looks like the obj is correctly asking for those materials.
Is there something I need to enable or otherwise do on the OpenGL end to make sure it's using these materials properly?
The ObjLoader and especially the MtlLoader it uses is very limited. Try using the new 3D api with fbx instead. Here's explained how to load a model: http://blog.xoppa.com/loading-models-using-libgdx/.
I found the very same issue, and that's exactly why I both reported it here:
https://github.com/libgdx/libgdx/issues/2441
and committed a fix to it here:
https://github.com/libgdx/libgdx/commit/d7e716351d26ddfba19ce9e0b3bdfb449dbc81b7
, supporting virtually all MTL parameters out there. Note that this is a WIP, and (hopefully) will get into trunk once it's finished.