I am generating images on fly from DICOM files using:
public ActionResult Generatemage()
{
FileContentResult data;
.....
objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m);
using (var memStream = new MemoryStream())
{
objImage.Save(memStream, ImageFormat.Png);
data = this.File(memStream.GetBuffer(), "image/png");
}
return data;
}
Can I store the image as a session variable so I can modify it using Point3D?
I tried to use:
Bitmap data = (Bitmap)Session["newimage"];
Got these two errors:
Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Web.Mvc.FileContentResult' and
A local variable named 'data' is already defined in this scope
I would appreciate your suggestions, thanks in advance.
Can I store the image as a session variable so I can modify it using
Point3D?
I suggest to not do that. If you have not read Nathanael's post on image resizing pitfalls then I suggest you do so now. It may be talking about resizing but it also give hints on working with images in general. On point #3 it says:
Serving a file from disk by loading it into memory. Think about how
much RAM your server has, how large a single image is, how long it has
to stay in memory before users fi downloading it, and how many
users you have requesting images.
In your particular case you can replace "before users finish downloading it" with "before Point3D finish processing the image". So, what I suggest is that you get a handle to that file, say maybe there's an Id that uniquely identifies a file per user, use that Id to retrieve the file when it's time to process it with Point3D, load it into a MemoryStream (assuming Point3D can work with mem. stream), process it, then dispose of it. In that manner you are only holding on to the image for the duration of "Point3D processing".
Cannot implicitly convert type 'System.Drawing.Bitmap' to
'System.Web.Mvc.FileContentResult' and A local variable named 'data'
is already defined in this scope
That is most probably because you have defined data as such:
FileContentResult data;
and then you are doing a:
Bitmap data = (Bitmap)Session["newimage"];
same variable of two different types within the same scope.
Related
My understanding of this was that perhaps CGPDFContext is to be used for editing PDF document data and CGPDFDocument is used for storing it, since the documentation doesn't list any ways to alter the content of a CGPDFDocument.
I'm also not quite sure what CGDataConsumer/Provider does. From reading the documentation I got the impression that the consumer/provider abstracts the relationship between the CG object and the CFData it writes to; so I don't have to do that myself. So I figured the following code would create a two page blank PDFdocument:
//Don't know exactly how large a PDF is so I gave it 1 MB for now
self->pdfData = CFDataCreateMutable(kCFAllocatorDefault, 1024);
self->consumerRef = CGDataConsumerCreateWithCFData(self->pdfData);
self.pdfRef = CGPDFContextCreate(self->consumerRef, NULL, NULL);
CGPDFContextBeginPage(self.pdfRef, NULL); //Creates a blank page?
CGPDFContextEndPage(self.pdfRef);
CGPDFContextBeginPage(self.pdfRef, NULL); //Creates a second blank page?
CGPDFContextEndPage(self.pdfRef);
//Copies the data from pdfRef's consumer into docRef's provider?
self.docRef = CGPDFDocumentCreateWithProvider(
CGDataProviderCreateWithCFData(
CFDataCreateCopy(kCFAllocatorDefault, self->pdfData)
));
It didn't work though, and NSLogging the first two pages of docRef returns NULL. I'm rather new at this, the C-Layer stuff in particular. Can someone explain to me the relationship between CGPDFContext, CGPDFDocument, CGDataConsumer & CGDataProvider and how I'd use them to create a blank PDF?
Your basic understanding is correct as far as I can see:
A CGPDFContext is a drawing context that "translates" everything that is drawn onto it to PDF instructions (typically for storage in a PDF file).
A CGPDFDocument is used to open an existing PDF file and get information from it.
When you want to create your own PDF file, you have two ways to do it as described here: https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGPDFContext/Reference/reference.html
Use "CGPDFContextCreate" which you pass a data consumer. The data consumer gets the data and can do with it as it pleases (you could create a data consumer that passes the PDF onto the clipboard for example).
Use "CGPDFContextCreateWithURL" which you pass a URL. In that case your data will be written to a PDF file at that URL.
If you want to use these functions, have a look at this page https://developer.apple.com/library/mac/documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF101 which explains in detail how to create PDF files with a data provider and without (simply to a PDF).
To figure out what is happening I would start by trying to write a simple PDF file to disk before writing one to a data provider and then using that data provider immediately to read it again. Without trying your code however, let me point out that you didn't use "CGPDFContextClose" which is described in the document as closing the PDF document and flushing all information to output. You could actually having a situation where stuff is cached and not written to your data provider yet, simply because you haven't forced that.
I do have lots of image files and need to store them in HDFS, in order to avoid the Small Files Problem, I am planning to store my image files using Sequence Files.
My problem is that I need to create a MapReduce program that processes only a selection of those files, I don't think it is a good idea to read all of the images content from the SequenceFile if I am only planning to process a few of them, also, more images can be added , if I create a new SequenceFile for each bunch of images, how would I know which SequenceFile contains the images I need to process?. In case I knew it would be overwhelming to filter manually the images before making input to mapper.
Please advice. Thanks!
If you can store your files in MapFile which is SequenceFile with an index, you can use MapFile.Reader to query some file by the key. For example,
MapFile.Reader reader = MapFile.Reader(fs, dirName, conf);
public byte[] get(String filename) {
TextWritable key = new TextWritable();
BytesWritable value = new BytesWritable();
if(reader.get(key,value) != null) {
return value.copyBytes();
}
else {
return null;
}
}
If you files are generated by a MapReduce application, you can use MapFileOutputFormat to output MapFile.
In addition, since you only need to process a few files, I think your don't need MapReduce in such process.
You could store the image files in HBase along with any other attributes of the images - that you may want to filter/query on. This will allow you to selectively query for images.
See this:
http://apache-hbase.679495.n3.nabble.com/Storing-images-in-Hbase-td4036184.html
http://www.slideshare.net/jacque74/hug-hbase-presentation
I developing an application for Windows Phone. And, here I have a requirement to store DateTime variable in isolated storage.
Is this possible? I know basic types like strings and ints etc can be stored.
Kindly help me thru this
You could store the value as Ticks in isolated storage and then when you read it just initialize a new DateTime instance from it. Ticks is defined as long so it should be straight forward to store it.
var valueToStore = DateTime.Now.Ticks;
// Save to isolated storage
var storedValue = ReadFromIsolatedStorage();
var dateTime = new DateTime(storedValue);
You can also use
DateTime.Parse(string);
Convert to string and save in isolated storage. And Retrieve using above statement from storage.
Some functions, like ExtAudioFileOpenURL, only accept URLs to as a path to a file. This is fine but what if your file is within a container or a memory buffer, is it still possible to create a URL to point to this?
eg
char * w = read_sample_bytes(...);
CFURLRef url = CFURLCreateForBuffer(..., w, ...);
ExtAudioFileOpenURL(url, &extAudioFile);
etc..
or will I have to extract the data to a temporary file and create a url to that?
Presumably, you would first create an AudioFileID with AudioFileInitializeWithCallbacks, then wrap the result using ExtAudioFileWrapAudioFileID for the ExtAudioFile APIs you will need. No CF/NS-URL is required to create/read files in memory using this approach.
You can't create a URL to a region of memory.
For your specific purpose, you'll have to either do what Justin suggested or use Audio Queue Services.
I have written a simple wp7 application. i am using wcf service to interact with the database. Now i want to store a part of user's info in the mobile also. this info needs to be accessible across the wp7 app.
I found multiple ways to do this like : isolated storage, resource files or static data in the app.xaml
Which one would be more suitable? as i may wish to edit the data in future...i may not opt for packaged files as they are read-only. also do not wish to lose data by storing in isolated storage.
Please suggest the most suitable option for me
Thanks in advance
Bindu
It sounds like you want to store downloaded data between uses of the app. In this case Isolated Storage is probably your best bet. It will remain in the phone's non-volatile memory and you will not lose it.
Details here
Resource files and static data in the app.xaml won't work for you since you want to be able to change these items at a later date since these will be read only.
I don't know what you are referring to when you say "lose data" by storing in IsolatedStorage. This is your best bet and is actually really easy to do. Here is an example of saving a simple boolean:
private void SaveSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["VibrationOn"] = VibrationOn;
}
Then to load it later:
private void LoadSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
bool vo;
if (settings.TryGetValue<bool>("VibrationOn", out vo))
VibrationOn = vo;
else
VibrationOn = true;
}
You would call your LoadSettings() method in the Application_Launching and Application_Activated events and then your SaveSettings() in the Application_Deactivated and Application_Closing events within your App.xaml.cs.
You can also serialize objects or write whole files.