فحص الـ الصور jpg قبل تشغيل البرنامج
#2
وعليكم السلام ورحمة الله وبركاته
فحص حجم الصورة:
كود :
function ReadMWord(f: TFileStream): Word; type TMotorolaWord = record case Byte of 0: (Value: Word); 1: (Byte1, Byte2: Byte); end; var MW: TMotorolaWord; begin { It would probably be better to just read these two bytes in normally } { and then do a small ASM routine to swap them. But we aren't talking } { about reading entire files, so I doubt the performance gain would be } { worth the trouble. } f.read(MW.Byte2, SizeOf(Byte)); f.read(MW.Byte1, SizeOf(Byte)); Result := MW.Value; end; procedure GetJPGSize(const sFile: string; var wWidth, wHeight: Word); const ValidSig: array[0..1] of Byte = ($FF, $D8); Parameterless = [$01, $D0, $D1, $D2, $D3, $D4, $D5, $D6, $D7]; var Sig: array[0..1] of byte; f: TFileStream; x: integer; Seg: byte; Dummy: array[0..15] of byte; Len: word; ReadLen: LongInt; begin FillChar(Sig, SizeOf(Sig), #0); f := TFileStream.Create(sFile, fmOpenRead); try ReadLen := f.read(Sig[0], SizeOf(Sig)); for x := Low(Sig) to High(Sig) do if Sig[x] <> ValidSig[x] then ReadLen := 0; if ReadLen > 0 then begin ReadLen := f.read(Seg, 1); while (Seg = $FF) and (ReadLen > 0) do begin ReadLen := f.read(Seg, 1); if Seg <> $FF then begin if (Seg = $C0) or (Seg = $C1) then begin ReadLen := f.read(Dummy[0], 3); { don't need these bytes } wHeight := ReadMWord(f); wWidth := ReadMWord(f); end else begin if not (Seg in Parameterless) then begin Len := ReadMWord(f); f.Seek(Len - 2, 1); f.read(Seg, 1); end else Seg := $FF; { Fake it to keep looping. } end; end; end; end; finally f.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); var wWidth, wHeight: Word; begin if OpenPictureDialog1.Execute then GetJPGSize(OpenPictureDialog1.FileName, wWidth, wHeight); Caption := IntToStr(wWidth) + ' X ' + IntToStr(wHeight); end;
لاستخراج الصورة من الـ Resource راجع مواضيع المنتدى...

للتنبيه: هذا غير كاف لحماية مصادر التطبيق من العبث!

بالتوفيق.
الرد


الردود في هذا الموضوع
فحص الـ الصور jpg قبل تشغيل البرنامج - بواسطة kachwahed - 09-10-2010, 11:07 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم